home *** CD-ROM | disk | FTP | other *** search
/ My First Encyclopedia & Spider-man Cartoon Maker / My First Encyclopedia & Spider-man Cartoon Maker.iso / paint / sounder.c < prev    next >
C/C++ Source or Header  |  1995-01-23  |  146KB  |  4,805 lines

  1. #define STRICT
  2.  
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <mmsystem.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <dir.h>
  9. #include <dos.h>
  10. #include <string.h>
  11.  
  12. #define TRUE                           1
  13. #define FALSE                          0
  14. #define NONE                           0
  15. #define IN                             1
  16. #define OUT                            2
  17.  
  18. #define IDS_NAME                       1
  19.  
  20. #define IDBT_CLEAR                     10
  21. #define IDBT_SNDPLAY                   20
  22. #define IDBT_MCICMD                    30
  23. #define IDBT_MCISTR                    40
  24. #define IDBT_TEXT                      50
  25. #define IDBT_STAMP                     60
  26. #define IDBT_MISC                      70
  27. #define IDBT_UNDO                      80
  28.  
  29. // COLORS
  30. #define RED         RGB(255,0,0)
  31. #define RED1        RGB(192,0,0)
  32. #define RED2        RGB(255,95,95) 
  33. #define DKRED       RGB(128,0,0)     // 4
  34. #define BLUE        RGB(0,0,255)
  35. #define BLUE1       RGB(0,0,192)  
  36. #define DKBLUE      RGB(0,0,128)     // 7
  37. #define GREEN       RGB(0,255,0)
  38. #define GREEN1      RGB(0,192,0)
  39. #define DKGREEN     RGB(0,128,0)     // 10
  40. #define CYAN        RGB(0,255,255)
  41. #define CYAN1       RGB(0,192,192)
  42. #define DKCYAN      RGB(0,128,128)   // 13
  43. #define MAGENTA     RGB(255,0,255)
  44. #define MAGENTA1    RGB(192,0,192)
  45. #define DKMAGENTA   RGB(128,0,128)   // 16
  46. #define YELLOW      RGB(255,255,0)
  47. #define YELLOW1     RGB(192,192,0)
  48. #define DKYELLOW    RGB(128,128,0)   // 19
  49. #define WHITE       RGB(255,255,255)
  50. #define GRAY        RGB(192,192,192)
  51. #define DKGRAY      RGB(128,128,128)  
  52. #define BLACK       RGB(0,0,0)       // 23
  53. #define BROWN       RGB(138,90,48)
  54. #define BROWN1      RGB(170,106,64)
  55. #define DKBROWN     RGB(202,127,79)   // 26
  56. #define TURQUOISE   RGB(43,199,139)
  57. #define TURQUOISE1  RGB(43,199,183)
  58. #define DKTURQUOISE RGB(43,171,199)   // 29
  59. #define ORANGE      RGB(255,207,176)
  60. #define ORANGE1     RGB(255,186,144)
  61. #define DKORANGE    RGB(255,165,112)   // 32
  62. #define ORANGE2     RGB(255,127,0)
  63.  
  64. // TOOLS
  65. #define PENCIL           1
  66. #define SPRAYCAN         2
  67. #define BUCKET           3
  68. #define RECTANGLE        4
  69. #define CIRCLE           5
  70. #define LINE             6
  71. #define MULTIPOLY        7
  72. #define SCISSORS         8
  73. #define FILLEDRECTANGLE  9
  74. #define FILLEDCIRCLE    10
  75. #define TRIANGLE        11
  76. #define FILLEDTRIANGLE  12
  77. #define QUILLPEN        13
  78. #define CHARCOALPENCIL  14
  79. #define GOOFYLINE       15
  80. #define SMALLERASER     16
  81. #define LARGEERASER     17
  82. #define ZIGZAG          18
  83. #define COLORDOT        19
  84. #define CHALK           20
  85. #define LINEA           21
  86. #define LINEB           22
  87. #define LINEC           23
  88. #define LINED           24
  89. #define PROPELLER       25
  90. #define KNIFE           26
  91. #define FLIPV           27
  92. #define FLIPH           28
  93. #define MOVE            29
  94. #define ICONDRAW        30
  95. #define COLORBOOK1      31
  96. #define COLORBOOK2      32
  97.  
  98.  
  99. // data initialized by first instance
  100. typedef struct tagSETUPDATA
  101.     {
  102.         char   szAppName[20]; // name of application
  103.     } SETUPDATA;
  104.  
  105. SETUPDATA SetUpData;
  106.  
  107. // Data that can be referenced throughout the
  108. // program but not passed to other instances
  109.  
  110. HANDLE    hInst;                              // hInstance of application
  111. HWND      hWndMain;                           // hWnd of main window
  112. HWND      phwnd;                              // hWnd of picture window
  113. char      szAppName[10];                      // name of application
  114.  
  115.  
  116. // General globals
  117. COLORREF  aColor[34];                         // color array
  118. POINT     polypoint[5000];                    // polygon array
  119. COLORREF  CurrentColor;
  120. HICON     TheIcon;
  121. HBITMAP   kabitmap;
  122. HDC       newhdc;                  
  123. HPEN      hOurPen;                       // how we're drawing now.
  124. HPALETTE  hwndpal;                       // our palette
  125. HWND      hwnd8;                         // undo button
  126.  
  127.  
  128.      // PAINTING VARS
  129. int       oldx, oldy,                         // Position of Cursor at MOUSEDOWN
  130.       xwas, ywas,                         // a Saved X/Y position
  131.       buttondown,                         // if we're drawing
  132.       DrawTool,                           // what tool to use
  133.       DrawWidth,                          // how big to make the line
  134.       ToolSet,                            // what tools are shown on screen
  135.       CurrentBoxPos,                      // outline current tool for user
  136.       LineSet,                            // BOOL to show if lines are on
  137.       polycount;                          // count of polygon points
  138.  
  139.      // TEXT VARS
  140. int      ReadyToDoText,
  141.       DoingText,
  142.       TextX,
  143.       TextY;
  144. HDC       savebitmapDC;
  145. HBITMAP   hsavebitmap;
  146. char      globaltextbuf[255];
  147. LOGFONT   MainFontRec;                        // our font record
  148. HFONT     hfont;                              // our font handle
  149.  
  150.     // DIRECTORY and FILE CONTROL VARS
  151. int       numfiles,                           // how many paintings in our directory.
  152.       firstfileshown,                     // what we are showing to the user
  153.       lastfileshown,                      // since we can show 5 at a time
  154.           Thumbnails;                         // flag if we're in Thumbnail mode
  155. char      ourdir[100];                        // our directory
  156. char      outdir[100];                        // output directory (for Ari Schindler Oct. 94)
  157. char      filearray[80][15];                  // list of paintings as file names
  158. char      commandline[255];                   // commandline
  159.  
  160.    // APPEARANCE and BEHAVIOUR CONTROL VARS
  161. int       hres,
  162.       vres,
  163.       colorbook,
  164.           kabitmapID;
  165. char      colorbmpname[15][15];
  166.  
  167.   // ADDED FOR K.A. 8/8/94 -- 11/7/94
  168. HDC       undodc;
  169. HBITMAP   undobmp;
  170. int       trashit, firstpaint, colorset,
  171.       firsttime, indrive, outdrive,
  172.       stupidpointer, stampsmear, aflag;
  173.  
  174. FILE         *fp;
  175. char         far stampwav[8][2500];
  176. char         far spraywav[2500];
  177. long         savelevel;
  178.  
  179.  
  180. // function prototypes
  181.  
  182. int      PASCAL        WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
  183. void                   InitPaint(HINSTANCE,HINSTANCE,LPSTR,int);
  184. void                   InitPaintFirst(HINSTANCE);
  185. void                   InitPaintAdded(HINSTANCE);
  186. void                   InitPaintEvery(HINSTANCE,int);
  187. LRESULT CALLBACK       PaintWndProc(HWND,UINT,WPARAM,LPARAM);
  188. LRESULT CALLBACK       PWinProc(HWND,UINT,WPARAM,LPARAM);
  189. void                   DoPaint(void);                 // main win WM_PAINT routine
  190. void                   Line(HDC, int, int, int, int); // graphics primitive
  191. void                   Box(HDC, int, int, int, int);  // graphics primitive
  192. void                   BoxAroundTool(int);            // draws red box around current tool
  193. void                   DrawLineSet(void);             // draws line sizes display
  194. void                   DrawNoSet(void);               // invalidates line sizes display
  195.                                                       //     and any mouse hit testing
  196. void                   NextToolSet(void);             // determine which tool set to use
  197. void                   PreviousToolSet(void);         //             DITTO
  198. void                   DrawTools1(void);              // drawing tools
  199. void                   DrawTools2(void);              // drawing tools
  200. void                   DrawTools3(void);              // drawing tools
  201. void                   DrawTools4(void);              // screen erasers
  202. void                   DrawTools5(void);              // effects
  203. void                   DrawTools6(void);              // computer ops
  204. void                   ExecuteErase(int);             // used to perform an erasure
  205. void                   ExecuteDisk(int);              // do a disk activity
  206. void                   BlankIconArea(int);            // blank top and draw arrow as needed 
  207. void                   InvertPic(void);               // color inversion
  208. void                   StretchPic(void);              // magnify +
  209. void                   ShrinkPic(void);               // magnify -
  210. void                   FindOurDirectory(void);        // where the faquarwe?
  211. void                   TheFileList(void);             // gets the list of painting files
  212. void                   DiskToPicSelected(void);       // user wants to select files
  213. void                   DisplayPics(void);             // show up to 5 pictures at top
  214. void                   MorePicsSelected(void);        // we have > 5 pics to show and the
  215.                                                       //     user wants to see them
  216. void                   UserPickedMe(int);             // show the picture that got picked
  217.                               // in the main picture window
  218. void                   PicToDiskSelected(void);       // SAVE picture
  219. void                   initpic(void);
  220. void                   ShowText(unsigned char);
  221. void                   cleanuptext(void);
  222.  
  223. void                   ParseCommandLine(void);
  224. void                   ColorBookPics(int);
  225. void                   ColorBookPicked(int);
  226. void                   DrawIcons(int);
  227. void                   TransmogrifyColor(void);
  228. void                   SaveToUndoPic(void);
  229. void                   PrintIt(void);
  230. void                   ColorTool(int);
  231. void                   HorizDitherPattern(void);
  232. void                   HorizDitherPattern2(void);
  233. void                   ColorAssign(void);
  234. void                   PlaySound(int);
  235. int                    DiskOK(void);
  236. void                   chthedir(int);
  237. void                   DrawLine(int, int, int, int, int, COLORREF);
  238.  
  239.  
  240. int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int cmdShow)
  241. {
  242.     MSG   msg;
  243.  
  244.  
  245.     strcpy(commandline,lpszCmdLine);
  246.     ParseCommandLine();
  247.     InitPaint(hInstance, hPrevInstance, lpszCmdLine, cmdShow);  
  248.  
  249.     while (GetMessage(&msg, NULL, 0, 0)){
  250.            TranslateMessage(&msg);
  251.        DispatchMessage(&msg);
  252.     }
  253.  
  254.     return(msg.wParam);
  255. }
  256.  
  257. // get the names of the bitmaps!
  258. void ParseCommandLine(void)
  259. {
  260.      int     i, j, placehold, thelen;
  261.      char    c, kabitmapname[15];
  262.  
  263.  
  264.      // reset the colorbook bitmap name char arrays
  265.      for(i = 0; i < 15; i++)
  266.      memset(colorbmpname[i],'\0',15);
  267.  
  268.      thelen = lstrlen(commandline);
  269.      if(lstrlen(commandline) < 5){
  270.     strncpy(kabitmapname,commandline,thelen);
  271.     colorbook = FALSE;
  272.         }
  273.      else{
  274.     colorbook = TRUE;
  275.     for(i = 0; i <= thelen; i++){
  276.         c = commandline[i];
  277.         if(c == ' ') break;
  278.         kabitmapname[i] = c;
  279.     }
  280.     placehold = ++i;
  281.  
  282.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  283.         c = commandline[i];
  284.         if(c == ' ') break;
  285.         colorbmpname[0][j] = c;
  286.     }
  287.     placehold = ++i;
  288.  
  289.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  290.         c = commandline[i];
  291.         if(c == ' ') break;
  292.         colorbmpname[1][j] = c;
  293.     }
  294.     placehold = ++i;
  295.  
  296.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  297.         c = commandline[i];
  298.         if(c == ' ') break;
  299.         colorbmpname[2][j] = c;
  300.     }
  301.     placehold = ++i;
  302.  
  303.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  304.         c = commandline[i];
  305.         if(c == ' ') break;
  306.         colorbmpname[3][j] = c;
  307.     }
  308.     placehold = ++i;
  309.  
  310.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  311.         c = commandline[i];
  312.         if(c == ' ') break;
  313.         colorbmpname[4][j] = c;
  314.     }
  315.     placehold = ++i;
  316.  
  317.         // more than 5 colorbook pictures
  318.  
  319.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  320.         c = commandline[i];
  321.         if(c == ' ') break;
  322.         colorbmpname[5][j] = c;
  323.     }
  324.     placehold = ++i;
  325.  
  326.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  327.         c = commandline[i];
  328.         if(c == ' ') break;
  329.         colorbmpname[6][j] = c;
  330.     }
  331.     placehold = ++i;
  332.  
  333.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  334.         c = commandline[i];
  335.         if(c == ' ') break;
  336.         colorbmpname[7][j] = c;
  337.     }
  338.     placehold = ++i;
  339.  
  340.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  341.         c = commandline[i];
  342.         if(c == ' ') break;
  343.         colorbmpname[8][j] = c;
  344.     }
  345.     placehold = ++i;
  346.  
  347.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  348.         c = commandline[i];
  349.         if(c == ' ') break;
  350.         colorbmpname[9][j] = c;
  351.     }
  352.     placehold = ++i;
  353.  
  354.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  355.         c = commandline[i];
  356.         if(c == ' ') break;
  357.         colorbmpname[10][j] = c;
  358.     }
  359.     placehold = ++i;
  360.  
  361.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  362.         c = commandline[i];
  363.         if(c == ' ') break;
  364.         colorbmpname[11][j] = c;
  365.     }
  366.     placehold = ++i;
  367.  
  368.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  369.         c = commandline[i];
  370.         if(c == ' ') break;
  371.         colorbmpname[12][j] = c;
  372.     }
  373.     placehold = ++i;
  374.  
  375.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  376.         c = commandline[i];
  377.         if(c == ' ') break;
  378.         colorbmpname[13][j] = c;
  379.     }
  380.     placehold = ++i;
  381.  
  382.     for(i = placehold, j = 0; i <= thelen; i++, j++){
  383.         c = commandline[i];
  384.         if(c == ' ') break;
  385.         colorbmpname[14][j] = c;
  386.     }
  387.     placehold = ++i;
  388.  
  389.      } // else
  390.      kabitmapID = 1;       // default
  391.      c = kabitmapname[0];
  392.      if(c == '1') kabitmapID = 1;
  393.      if(c == '2') kabitmapID = 2;
  394.      if(c == '3') kabitmapID = 3;
  395.      if(c == '4') kabitmapID = 4;
  396.      if(c == '5') kabitmapID = 5;
  397.      if(c == '6') kabitmapID = 6;
  398.      if(c == '7') kabitmapID = 7;
  399.      if(c == '8') kabitmapID = 8;
  400.      if(c == '9') kabitmapID = 9;
  401.      if(c == 'A') kabitmapID = 10;
  402.      firsttime = TRUE;
  403.      aflag = FALSE;
  404. }
  405.  
  406. #pragma argsused
  407. void InitPaint(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpszCmdLine,int cmdShow)
  408. {
  409.     if (!hPrevInstance)                  // if no previous instance, this is first
  410.         InitPaintFirst(hInstance);
  411.     else
  412.         InitPaintAdded(hPrevInstance);   // this is not first instance
  413.  
  414.     InitPaintEvery(hInstance, cmdShow);  // initialization for all instances
  415. }
  416.  
  417. void InitPaintFirst(HINSTANCE hInstance)
  418. {
  419.      WNDCLASS wcPaintClass;
  420.  
  421.      LoadString(hInstance, IDS_NAME, (LPSTR) SetUpData.szAppName, 10);
  422.  
  423.      wcPaintClass.lpszClassName = SetUpData.szAppName;
  424.      wcPaintClass.hInstance     = hInstance;
  425.      wcPaintClass.lpfnWndProc   = PaintWndProc;
  426.      wcPaintClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  427.      wcPaintClass.hIcon         = NULL;
  428.      wcPaintClass.lpszMenuName  = NULL;
  429.      wcPaintClass.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  430.      wcPaintClass.style         = CS_HREDRAW | CS_VREDRAW;
  431.      wcPaintClass.cbClsExtra    = 0;
  432.      wcPaintClass.cbWndExtra    = 0;
  433.  
  434.      RegisterClass(&wcPaintClass);    
  435. }
  436.  
  437. //*******************************************************************
  438. //                 done only for added instances
  439. //*******************************************************************
  440. void InitPaintAdded(
  441. HINSTANCE hPrevInstance)
  442. {
  443.     GetInstanceData(hPrevInstance, (BYTE*)&SetUpData, sizeof(SETUPDATA));
  444. }
  445.  
  446. //*******************************************************************
  447. //                    done for every instance
  448. //*******************************************************************
  449. void InitPaintEvery(HINSTANCE hInstance,int cmdShow)
  450. {
  451.      
  452.      HWND    thescreen;
  453.      HDC     hdc;
  454.      RECT    arect;
  455.      
  456.  
  457.      hInst = hInstance;
  458.      // Create applications main window.
  459.      thescreen = GetDesktopWindow();
  460.      hdc = GetDC(thescreen);
  461.      hres = GetDeviceCaps(hdc,HORZRES);
  462.      vres = GetDeviceCaps(hdc,VERTRES);
  463.      ReleaseDC(thescreen, hdc);
  464.      arect.top = 0;
  465.      arect.left = 0;
  466.      arect.right = hres;
  467.      arect.bottom = vres;
  468.      AdjustWindowRect(&arect,WS_BORDER|WS_POPUP,FALSE);
  469.  
  470.      hWndMain = CreateWindow(
  471.                      SetUpData.szAppName,     // window class name
  472.                  SetUpData.szAppName,     // window title
  473.                  WS_BORDER|WS_POPUP,   // type of window
  474.                  0,         // x  window location
  475.                  0,         // y
  476.                  arect.right,           // cx and size
  477.                  arect.bottom,           // cy
  478.                  NULL,                    // no parent for this window
  479.                  NULL,                    // use the class menu
  480.                  hInstance,               // who created this window
  481.                  NULL                     // no parms to pass on
  482.      );
  483.  
  484.       // Update display of main window.
  485.      ShowWindow(hWndMain, cmdShow);
  486.      UpdateWindow(hWndMain);
  487. }
  488.  
  489.  
  490. #pragma argsused
  491. LRESULT CALLBACK PWinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  492. {
  493.    PAINTSTRUCT  ps;
  494.    HDC          hdc;
  495.    POINT        pCursor;
  496.    HBRUSH       hBrush, hBrush1, hobr;
  497.    HPEN         hPen1, hop;
  498.    RECT         rect;
  499.    int          i, j, k, x, y, halfx;
  500.    LOGBRUSH     logbrush;
  501.    char         c, buf[100], buf2[255];
  502.    HPALETTE     oldpal, oldpal2;
  503.    COLORREF     acolour;
  504.  
  505.  
  506.    switch(message){
  507.        case WM_CREATE:
  508.             // create font...
  509.         MainFontRec.lfHeight = 36;
  510.             MainFontRec.lfWidth = 16;
  511.             MainFontRec.lfEscapement = 0;
  512.         MainFontRec.lfOrientation = 0;
  513.             MainFontRec.lfWeight = FW_BOLD;
  514.             MainFontRec.lfItalic = 0;
  515.             MainFontRec.lfUnderline = 0;
  516.             MainFontRec.lfStrikeOut = 0;
  517.             MainFontRec.lfCharSet = ANSI_CHARSET;
  518.         MainFontRec.lfOutPrecision = OUT_DEFAULT_PRECIS;
  519.             MainFontRec.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  520.             MainFontRec.lfQuality = PROOF_QUALITY;
  521.             MainFontRec.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
  522.         strcpy(MainFontRec.lfFaceName,"Times New Roman");
  523.         hdc = GetDC(hWnd);
  524.         undodc = CreateCompatibleDC(hdc);
  525.         undobmp = CreateCompatibleBitmap(hdc,hres-50,vres-50);
  526.         SelectObject(undodc,undobmp);
  527.         ReleaseDC(hWnd,hdc);
  528.         break;
  529.        case WM_DESTROY:
  530.         DeleteDC(undodc);
  531.         DeleteObject(undobmp);
  532.         memset(buf,100,'\0');
  533.         strcpy(buf,"close midi");   
  534.         mciSendString(buf, buf2, 255, hWnd);
  535.         break;
  536.        case WM_PAINT:
  537.         if(firsttime == TRUE){
  538.            hdc = GetDC(hWnd);
  539.            BitBlt(undodc,0,0,hres-50,vres-50,NULL,0,0,WHITENESS);
  540.            ReleaseDC(hWnd,hdc);
  541.            firsttime = FALSE;
  542.            memset(buf,100,'\0');               // get the buffer ready
  543.            chthedir(IN);                      // make sure we're in our directory
  544.            switch(kabitmapID){
  545.                    case 1:
  546.               strcpy(buf,"rm0cboot.wav");            
  547.               break;
  548.            case 3:
  549.               strcpy(buf,"rm3cboot.wav");
  550.               break;
  551.            case 4:
  552.               strcpy(buf,"rm4cboot.wav");
  553.               break;
  554.            case 5:
  555.               strcpy(buf,"rm4dboot.wav");
  556.               break;
  557.            case 6:
  558.               strcpy(buf,"rm6cboot.wav");
  559.               break;
  560.            case 7:
  561.               strcpy(buf,"rm7cboot.wav");
  562.               break;
  563.                }     
  564.            sndPlaySound(buf,SND_ASYNC);         // and play it...
  565.            if(kabitmapID == 5){
  566.           chthedir(IN);                          // we're in the right directory...
  567.               memset(buf,100,'\0');                   // clear out the buffer
  568.               strcpy(buf,"Open painter.mid alias midi");  // (this is simple enough, eh?)
  569.  
  570.               mciSendString(buf, buf2, 255, hWnd);    // buf2 is a message buffer
  571.                             // in case MMSYSTEM complains.
  572.                             // you don't really need to look
  573.                             // at it unless you want to do
  574.                                                     // something upon failure.
  575.               memset(buf,100,'\0');
  576.               strcpy(buf,"Play midi from 0 notify");         // and then tell it to play.
  577.               mciSendString(buf, buf2, 255, hWnd);
  578.            }
  579.            else{
  580.               chthedir(IN);                          // we're in the right directory...
  581.               memset(buf,100,'\0');                   // clear out the buffer
  582.               strcpy(buf,"Open crayonme.mid alias midi");  // (this is simple enough, eh?)
  583.  
  584.               mciSendString(buf, buf2, 255, hWnd);    // buf2 is a message buffer
  585.                             // in case MMSYSTEM complains.
  586.                             // you don't really need to look
  587.                             // at it unless you want to do
  588.                                                     // something upon failure.
  589.               memset(buf,100,'\0');
  590.               strcpy(buf,"Play midi from 0 notify");         // and then tell it to play.
  591.               mciSendString(buf, buf2, 255, hWnd);
  592.            }
  593.         }
  594.             // This is what we get in a normal paint...
  595.         BeginPaint(hWnd,&ps);
  596.         oldpal = SelectPalette(ps.hdc, hwndpal, FALSE);
  597.         RealizePalette(ps.hdc);
  598.         BitBlt(ps.hdc,0,0,hres-50,vres-50,undodc,0,0,SRCCOPY);
  599.         SelectPalette(ps.hdc, oldpal, FALSE);
  600.         EndPaint(hWnd,&ps);
  601.         if(colorbook == FALSE) DrawTools1();
  602.         break;
  603.        case MM_MCINOTIFY:
  604.         if(wParam != MCI_NOTIFY_FAILURE){  // if not nfg
  605.            memset(buf,100,'\0');
  606.            strcpy(buf,"Play midi from 0 notify");   
  607.            mciSendString(buf, buf2, 255, hWnd);
  608.         }
  609.             break;
  610.        case WM_RBUTTONDOWN:
  611.         buttondown = FALSE;
  612.         break;
  613.        case WM_LBUTTONDOWN:
  614.         pCursor = MAKEPOINT(lParam);
  615.         oldx = pCursor.x;
  616.         oldy = pCursor.y;
  617.         if(DoingText == TRUE){
  618.            cleanuptext();
  619.            break;
  620.         }
  621.         if(ReadyToDoText == TRUE){
  622.            TextX = pCursor.x;
  623.            TextY = pCursor.y;
  624.            ReadyToDoText = FALSE;
  625.            DoingText = TRUE;
  626.            hdc = GetDC(hWnd);
  627.            oldpal = SelectPalette(hdc, hwndpal, FALSE);
  628.            RealizePalette(hdc);
  629.            memset(globaltextbuf,'\0',255);
  630.            savebitmapDC = CreateCompatibleDC(hdc);
  631.            hsavebitmap = CreateCompatibleBitmap(hdc,hres-50,vres-50);
  632.            SelectObject(savebitmapDC,hsavebitmap);
  633.            oldpal2 = SelectPalette(savebitmapDC, hwndpal, FALSE);
  634.            RealizePalette(savebitmapDC);
  635.            BitBlt(savebitmapDC,0,0,hres-50,vres-50,hdc,0,0,SRCCOPY);
  636.            SelectPalette(savebitmapDC, oldpal2, FALSE);
  637.            SelectPalette(hdc, oldpal, FALSE);
  638.            ReleaseDC(hWnd,hdc);
  639.                BlankIconArea(0);
  640.            SetFocus(hWndMain);
  641.            ShowText(' ');
  642.                break;
  643.         }
  644.         if(colorbook == TRUE){
  645.            hdc = GetDC(hWnd);
  646.            oldpal = SelectPalette(hdc, hwndpal, FALSE);
  647.            RealizePalette(hdc);
  648.            if(DrawTool == COLORBOOK1){
  649.           hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  650.           j = 1;
  651.                }
  652.            else{
  653.           hBrush = CreateSolidBrush(WHITE);
  654.           j = 2;
  655.                }
  656.            hobr = SelectObject(hdc,hBrush);
  657.            if(GetPixel(hdc,oldx,oldy) != BLACK){
  658.                   if(j == 1)
  659.              PlaySound(14); // paint sound if painting
  660.           else
  661.                      PlaySound(1);  // vacuum sound otherwise
  662.           ExtFloodFill(hdc,oldx,oldy,GetPixel(hdc,oldx,oldy) | 0x2000000L,FLOODFILLSURFACE);
  663.            }
  664.            SelectObject(hdc,hobr);
  665.            SelectPalette(hdc, oldpal, FALSE);
  666.            ReleaseDC(hWnd,hdc);
  667.            DeleteObject(hBrush);
  668.            break;
  669.         }
  670.         switch(DrawTool){
  671.            case ICONDRAW:
  672.             hdc = GetDC(hWnd);
  673.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  674.             RealizePalette(hdc);
  675.             j = random(8);
  676.             sndPlaySound(stampwav[j],SND_MEMORY);
  677.             DrawIcon(hdc,oldx - 16,oldy-16,TheIcon);
  678.             SelectPalette(hdc, oldpal, FALSE);
  679.             ReleaseDC(hWnd,hdc);
  680.                     if(stampsmear == TRUE)
  681.                buttondown = TRUE;
  682.             break;
  683.            case PENCIL:
  684.                     DrawLine(oldx, oldy,oldx+1,oldy,DrawWidth,CurrentColor);
  685.             buttondown = TRUE;
  686.             break;
  687.            case COLORDOT:
  688.             hdc = GetDC(hWnd);
  689.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  690.             RealizePalette(hdc);
  691.             j = random(15);
  692.                     k = random(20);
  693.             hOurPen = CreatePen(PS_SOLID,1,aColor[j] | 0x2000000L);
  694.             hop = SelectObject(hdc,hOurPen);
  695.             hBrush = CreateSolidBrush(aColor[j] | 0x2000000L);
  696.             hobr = SelectObject(hdc,hBrush);
  697.             Ellipse(hdc,oldx - k,oldy - k,oldx + k,oldy + k);
  698.             SelectObject(hdc,hop);
  699.             SelectObject(hdc,hobr);
  700.             SelectPalette(hdc, oldpal, FALSE);
  701.             ReleaseDC(hWnd,hdc);
  702.             DeleteObject(hOurPen);
  703.             DeleteObject(hBrush);
  704.             buttondown = TRUE;
  705.             break;
  706.            case ZIGZAG:
  707.             PlaySound(12);
  708.                 DrawLine(oldx,oldy,oldx,oldy,DrawWidth,CurrentColor);
  709.             buttondown = TRUE;
  710.             break;
  711.            case LINEA:
  712.             PlaySound(107);
  713.             k = DrawWidth * 2;
  714.             DrawLine(oldx - k,oldy + k,oldx + k,oldy - k,DrawWidth,CurrentColor);
  715.             buttondown = TRUE;
  716.             break;
  717.            case LINEB:
  718.             PlaySound(47);
  719.             k = DrawWidth * 2;
  720.             DrawLine(oldx - k,oldy - k,oldx + k,oldy + k,DrawWidth,CurrentColor);
  721.             buttondown = TRUE;
  722.             break;
  723.            case LINEC:
  724.             PlaySound(57);
  725.             k = DrawWidth * 2;
  726.             DrawLine(oldx,oldy - k,oldx,oldy + k,DrawWidth,CurrentColor);
  727.             buttondown = TRUE;
  728.             break;
  729.            case LINED:
  730.             PlaySound(20);
  731.             k = DrawWidth * 2;
  732.             DrawLine(oldx - k,oldy,oldx + k,oldy,DrawWidth,CurrentColor);
  733.             buttondown = TRUE;
  734.             break;
  735.            case QUILLPEN:
  736.             PlaySound(67);
  737.             DrawLine(oldx,oldy,oldx,oldy,4,CurrentColor);
  738.             buttondown = TRUE;
  739.             break;
  740.            case CHARCOALPENCIL:
  741.             PlaySound(108);
  742.             DrawLine(oldx,oldy,oldx,oldy,2,CurrentColor);
  743.             buttondown = TRUE;
  744.             break;
  745.            case SPRAYCAN:
  746.             PlaySound(83);
  747.             hdc = GetDC(hWnd);
  748.             SelectPalette(hdc, hwndpal, FALSE);
  749.             RealizePalette(hdc);
  750.             for(i = 0;i < 25; i++){
  751.             j = random(DrawWidth * 8);
  752.             k = random(DrawWidth * 8);
  753.             if(j%2 == 0) j = j * -1;
  754.             if(k%2 != 0) k = k * -1;
  755.             SetPixel(hdc,oldx + j, oldy + k,CurrentColor | 0x2000000L);
  756.             }
  757.             ReleaseDC(hWnd,hdc);
  758.             buttondown = TRUE;
  759.             break;
  760.            case CHALK:
  761.             hdc = GetDC(hWnd);
  762.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  763.             RealizePalette(hdc);
  764.                     PlaySound(5);
  765.             for(i = 0;i < 25; i++){
  766.             j = random(7);
  767.             k = random(8);
  768.             if(j%2 == 0) j = j * -1;
  769.             if(k%2 != 0) k = k * -1;
  770.             SetPixel(hdc,oldx + j, oldy + k,CurrentColor | 0x2000000L);
  771.             }
  772.             SelectPalette(hdc, oldpal, FALSE);
  773.             ReleaseDC(hWnd,hdc);
  774.             DrawLine(oldx,oldy,oldx,oldy,DrawWidth,CurrentColor);
  775.             buttondown = TRUE;
  776.             break;
  777.            case GOOFYLINE:
  778.             PlaySound(3);
  779.             for(i = 0;i < 10; i++){
  780.             j = random(DrawWidth * 8);
  781.             k = random(DrawWidth * 8);
  782.             if(j%2 == 0) j *= -1;
  783.             if(k%2 != 0) k *= -1;
  784.             DrawLine(oldx,oldy,oldx + j, oldy + k,DrawWidth,CurrentColor);
  785.             }
  786.             buttondown = TRUE;
  787.             break;
  788.            case BUCKET:
  789.             hdc = GetDC(hWnd);
  790.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  791.             RealizePalette(hdc);
  792.             acolour = GetPixel(hdc,oldx,oldy);
  793.             if(acolour == CurrentColor){
  794.                SelectPalette(hdc, oldpal, FALSE);
  795.                ReleaseDC(hWnd,hdc);
  796.                break;
  797.             }
  798.             hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  799.             hobr = SelectObject(hdc,hBrush);
  800.             PlaySound(14);
  801.             ExtFloodFill(hdc,oldx,oldy,GetPixel(hdc,oldx,oldy)| 0x2000000L, FLOODFILLSURFACE);
  802.             SelectObject(hdc, hobr);
  803.             SelectPalette(hdc, oldpal, FALSE);
  804.             ReleaseDC(hWnd,hdc);
  805.             DeleteObject(hBrush);
  806.             break;
  807.            case SMALLERASER:
  808.             PlaySound(41);
  809.             hdc = GetDC(hWnd);
  810.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  811.             RealizePalette(hdc);
  812.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  813.                     hPen1 = CreatePen(PS_SOLID,1,BLACK);
  814.             hop = SelectObject(hdc,hOurPen);
  815.             hBrush = CreateSolidBrush(WHITE);
  816.             hobr = SelectObject(hdc,hBrush);
  817.             x = oldx - 10;
  818.             y = oldy - 10;
  819.             Rectangle(hdc,x,y,x+20,y+20);
  820.             SelectObject(hdc, hop);
  821.                     hop = SelectObject(hdc,hPen1);
  822.             Box(hdc,x,y,x+20,y+20);
  823.             SelectObject(hdc, hobr);
  824.             SelectObject(hdc, hop);
  825.             SelectPalette(hdc, oldpal, FALSE);
  826.             ReleaseDC(hWnd,hdc);
  827.             DeleteObject(hBrush);
  828.             DeleteObject(hOurPen);
  829.             DeleteObject(hPen1);
  830.             buttondown = TRUE;
  831.             break;
  832.            case LARGEERASER:
  833.             hdc = GetDC(hWnd);
  834.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  835.             RealizePalette(hdc);
  836.             PlaySound(1);
  837.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  838.             hPen1 = CreatePen(PS_SOLID,1,BLACK);
  839.             hop = SelectObject(hdc,hOurPen);
  840.             hBrush = CreateSolidBrush(WHITE);
  841.             hobr = SelectObject(hdc,hBrush);
  842.             x = oldx - 20;
  843.             y = oldy - 20;
  844.             Rectangle(hdc,x,y,x+40,y+40);
  845.             SelectObject(hdc, hop);
  846.             hop = SelectObject(hdc,hPen1);
  847.             Box(hdc,x,y,x+40,y+40);
  848.             SelectObject(hdc, hobr);
  849.             SelectObject(hdc, hop);
  850.             SelectPalette(hdc, oldpal, FALSE);
  851.             ReleaseDC(hWnd,hdc);
  852.             DeleteObject(hOurPen);
  853.             DeleteObject(hBrush);
  854.             DeleteObject(hPen1);
  855.             buttondown = TRUE;
  856.             break;
  857.            case MULTIPOLY:
  858.                     polycount = 0;
  859.             xwas = oldx;
  860.             ywas = oldy;
  861.             polypoint[polycount].x = oldx;
  862.             polypoint[polycount++].y = oldy;
  863.             buttondown = TRUE;
  864.             break;
  865.            case KNIFE:
  866.                     polycount = 0;
  867.             xwas = oldx;
  868.             ywas = oldy;
  869.             polypoint[polycount].x = oldx;
  870.             polypoint[polycount++].y = oldy;
  871.             buttondown = TRUE;
  872.             break;
  873.            case SCISSORS:
  874.                     PlaySound(80);
  875.             xwas = oldx;
  876.             ywas = oldy;
  877.             buttondown = TRUE;
  878.             break;
  879.            case PROPELLER:
  880.             PlaySound(43);
  881.             xwas = oldx;
  882.             ywas = oldy;
  883.             buttondown = TRUE;
  884.             break;
  885.            case LINE:
  886.            case RECTANGLE:
  887.            case FLIPH:
  888.            case FLIPV:
  889.            case CIRCLE:
  890.            case FILLEDCIRCLE:
  891.            case FILLEDRECTANGLE:
  892.            case TRIANGLE:
  893.                case FILLEDTRIANGLE:
  894.             xwas = oldx;
  895.             ywas = oldy;
  896.             buttondown = TRUE;
  897.             break;
  898.             } // DrawTool switch
  899.             SetCapture(phwnd);
  900.         break;
  901.        case WM_MOUSEMOVE:
  902.         if(buttondown){
  903.            pCursor = MAKEPOINT(lParam);
  904.            switch(DrawTool){
  905.           case ICONDRAW:
  906.                hdc = GetDC(hWnd);
  907.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  908.                RealizePalette(hdc);
  909.                j = random(8);
  910.                sndPlaySound(stampwav[j],SND_MEMORY);
  911.                DrawIcon(hdc,pCursor.x - 16,pCursor.y-16,TheIcon);
  912.                SelectPalette(hdc, oldpal, FALSE);
  913.                ReleaseDC(hWnd,hdc);
  914.                        break;
  915.           case LINEA:
  916.                k = DrawWidth * 2;
  917.                for(i = (k * -1); i < k; i++)
  918.                DrawLine(oldx + i,oldy + (i * -1),pCursor.x + i,pCursor.y + (i * -1),DrawWidth,CurrentColor);
  919.                oldx = pCursor.x;
  920.                oldy = pCursor.y;
  921.                break;
  922.           case LINEB:
  923.                k = DrawWidth * 2;
  924.                for(i = (k * -1); i < k; i++)
  925.                DrawLine(oldx + i, oldy + i, pCursor.x + i, pCursor.y + i,DrawWidth,CurrentColor);
  926.                oldx = pCursor.x;
  927.                oldy = pCursor.y;
  928.                break;
  929.           case LINEC:
  930.                k = DrawWidth * 2;
  931.                for(i = (k * -1); i < k; i++)
  932.                    DrawLine(oldx,pCursor.y - i,pCursor.x,pCursor.y + i,DrawWidth,CurrentColor);
  933.                oldx = pCursor.x;
  934.                oldy = pCursor.y;
  935.                break;
  936.           case LINED:
  937.                k = DrawWidth * 2;
  938.                for(i = (k * -1); i < k; i++)
  939.                    DrawLine(pCursor.x - i,oldy,pCursor.x + i,pCursor.y,DrawWidth,CurrentColor);
  940.                oldx = pCursor.x;
  941.                oldy = pCursor.y;
  942.                break;
  943.           case COLORDOT:
  944.                j = random(8);
  945.                sndPlaySound(stampwav[j],SND_MEMORY);
  946.                hdc = GetDC(hWnd);
  947.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  948.                RealizePalette(hdc);
  949.                j = random(15);
  950.                        k = random(20);
  951.                hOurPen = CreatePen(PS_SOLID,1,aColor[j] | 0x2000000L);
  952.                hop = SelectObject(hdc,hOurPen);
  953.                hBrush = CreateSolidBrush(aColor[j] | 0x2000000L);
  954.                hop = SelectObject(hdc,hBrush);
  955.                Ellipse(hdc,pCursor.x - k,pCursor.y - k,pCursor.x + k,pCursor.y + k);
  956.                SelectObject(hdc,hop);
  957.                SelectObject(hdc,hobr);
  958.                SelectPalette(hdc, oldpal, FALSE);
  959.                ReleaseDC(hWnd,hdc);
  960.                DeleteObject(hOurPen);
  961.                DeleteObject(hBrush);
  962.                break;
  963.           case SMALLERASER:
  964.                hdc = GetDC(hWnd);
  965.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  966.                RealizePalette(hdc);
  967.                hOurPen = CreatePen(PS_SOLID,1,WHITE);
  968.                hPen1 = CreatePen(PS_SOLID,1,BLACK);
  969.                x = oldx - 10;
  970.                y = oldy - 10;
  971.                hop = SelectObject(hdc,hOurPen);
  972.                Box(hdc,x,y,x+20,y+20);
  973.                hBrush = CreateSolidBrush(WHITE);
  974.                hobr = SelectObject(hdc,hBrush);
  975.                x = pCursor.x - 10;
  976.                y = pCursor.y - 10;
  977.                Rectangle(hdc,x,y,x+20,y+20);
  978.                SelectObject(hdc,hop);
  979.                hop = SelectObject(hdc,hPen1);
  980.                Box(hdc,x,y,x+20,y+20);
  981.                oldx = pCursor.x;
  982.                oldy = pCursor.y;
  983.                SelectObject(hdc,hop);
  984.                SelectObject(hdc,hobr);
  985.                SelectPalette(hdc, oldpal, FALSE);
  986.                ReleaseDC(hWnd,hdc);
  987.                DeleteObject(hBrush);
  988.                DeleteObject(hOurPen);
  989.                DeleteObject(hPen1);
  990.                break;
  991.               case LARGEERASER:
  992.                hdc = GetDC(hWnd);
  993.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  994.                RealizePalette(hdc);
  995.                hOurPen = CreatePen(PS_SOLID,1,WHITE);
  996.                hPen1 = CreatePen(PS_SOLID,1,BLACK);
  997.                x = oldx - 20;
  998.                y = oldy - 20;
  999.                hop = SelectObject(hdc,hOurPen);
  1000.                Box(hdc,x,y,x+40,y+40);
  1001.                hBrush = CreateSolidBrush(WHITE);
  1002.                hobr = SelectObject(hdc,hBrush);
  1003.                x = pCursor.x - 20;
  1004.                y = pCursor.y - 20;
  1005.                Rectangle(hdc,x,y,x+40,y+40);
  1006.                SelectObject(hdc,hop);
  1007.                hop = SelectObject(hdc,hPen1);
  1008.                Box(hdc,x,y,x+40,y+40);
  1009.                oldx = pCursor.x;
  1010.                oldy = pCursor.y;
  1011.                SelectObject(hdc,hop);
  1012.                SelectObject(hdc,hobr);
  1013.                SelectPalette(hdc, oldpal, FALSE);
  1014.                ReleaseDC(hWnd,hdc);
  1015.                DeleteObject(hBrush);
  1016.                DeleteObject(hOurPen);
  1017.                DeleteObject(hPen1);
  1018.                break;
  1019.                   case PENCIL:
  1020.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,DrawWidth,CurrentColor);
  1021.                    oldx = pCursor.x;
  1022.                oldy = pCursor.y;
  1023.                break;
  1024.           case QUILLPEN:
  1025.                if(pCursor.x > oldx) x = pCursor.x - oldx;
  1026.                else                 x = oldx - pCursor.x;
  1027.  
  1028.                if(pCursor.y > oldy) y = pCursor.y - oldy;
  1029.                else                 y = oldy - pCursor.y;
  1030.  
  1031.                if(x > y)            j = x;
  1032.                else                 j = y;
  1033.  
  1034.                if(j < 5) k = 4;
  1035.                if(j >= 5 && j < 10) k = 3;
  1036.                if(j >= 10 && j < 20) k = 2;
  1037.                if(j >= 20) k = 1;
  1038.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,k,CurrentColor);
  1039.                    oldx = pCursor.x;
  1040.                    oldy = pCursor.y;
  1041.                break;
  1042.           case CHARCOALPENCIL:
  1043.                if(pCursor.x > oldx)
  1044.               x = pCursor.x - oldx;
  1045.                else
  1046.               x = oldx - pCursor.x;
  1047.                if(pCursor.y > oldy)
  1048.               y = pCursor.y - oldy;
  1049.                else
  1050.               y = oldy - pCursor.y;
  1051.                if(x > y)
  1052.               j = x;
  1053.                else
  1054.               j = y;
  1055.                if(j < 5) k = 2;
  1056.                if(j >= 5 && j < 10) k = 3;
  1057.                if(j >= 10 && j < 20) k = 4;
  1058.                if(j >= 20) k = 5;        
  1059.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,k,CurrentColor);
  1060.                    oldx = pCursor.x;
  1061.                    oldy = pCursor.y;
  1062.                break;
  1063.           case MULTIPOLY:
  1064.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,1,CurrentColor);
  1065.                    oldx = pCursor.x;
  1066.                oldy = pCursor.y;
  1067.                polypoint[polycount].x = oldx;
  1068.                polypoint[polycount++].y = oldy;
  1069.                break;
  1070.           case KNIFE:
  1071.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,1,WHITE);
  1072.                    oldx = pCursor.x;
  1073.                oldy = pCursor.y;
  1074.                polypoint[polycount].x = oldx;
  1075.                polypoint[polycount++].y = oldy;
  1076.                break;
  1077.           case SPRAYCAN:
  1078.                hdc = GetDC(hWnd);
  1079.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1080.                RealizePalette(hdc);
  1081.                for(i = 0;i < 25; i++){
  1082.                j = random(DrawWidth * 8);
  1083.                    k = random(DrawWidth * 8);
  1084.                if(j%2 != 0) j *= -1;
  1085.                if(k%2 == 0) k *= -1;
  1086.                SetPixel(hdc,pCursor.x + j, pCursor.y + k,CurrentColor | 0x2000000L);
  1087.                }
  1088.                SelectPalette(hdc, oldpal, FALSE);
  1089.                ReleaseDC(hWnd,hdc);
  1090.                break;
  1091.           case CHALK:
  1092.                hdc = GetDC(hWnd);
  1093.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1094.                RealizePalette(hdc);
  1095.                for(i = 0;i < 25; i++){
  1096.                    j = random(7);
  1097.                    k = random(8);
  1098.                if(j%2 == 0) j *= -1;
  1099.                if(k%2 != 0) k *= -1;
  1100.                SetPixel(hdc,oldx + j, oldy + k,CurrentColor | 0x2000000L);
  1101.                }
  1102.                SelectPalette(hdc, oldpal, FALSE);
  1103.                ReleaseDC(hWnd,hdc);
  1104.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,10,CurrentColor);
  1105.                oldx = pCursor.x;
  1106.                oldy = pCursor.y;
  1107.                break;
  1108.           case GOOFYLINE:
  1109.                for(i = 0;i < 10; i++){
  1110.                    j = random(DrawWidth * 12);
  1111.                k = random(DrawWidth * 12);
  1112.                if(j%2 == 0) j *= -1;
  1113.                if(k%2 != 0) k *= -1;
  1114.                DrawLine(pCursor.x,pCursor.y,pCursor.x + j, pCursor.y + k,DrawWidth,CurrentColor);
  1115.                }
  1116.                        break;
  1117.           case LINE:
  1118.                hdc = GetDC(hWnd);
  1119.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1120.                RealizePalette(hdc);
  1121.                SetROP2(hdc,R2_XORPEN);
  1122.                hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1123.                hop = SelectObject(hdc,hOurPen);
  1124.                Line(hdc,oldx,oldy,xwas,ywas);
  1125.                Line(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1126.                xwas = pCursor.x;
  1127.                ywas = pCursor.y;
  1128.                SelectPalette(hdc, oldpal, FALSE);
  1129.                SelectObject(hdc,hop);
  1130.                ReleaseDC(hWnd,hdc);
  1131.                DeleteObject(hOurPen);
  1132.                break;
  1133.           case PROPELLER:
  1134.                if(pCursor.x > oldx)
  1135.               x = oldx - (pCursor.x - oldx);
  1136.                else
  1137.               x = oldx + (oldx - pCursor.x);
  1138.                if(pCursor.y > oldy)
  1139.               y = oldy - (pCursor.y - oldy);
  1140.                else
  1141.               y = oldy + (oldy - pCursor.y);
  1142.                DrawLine(oldx,oldy,x,y,1,CurrentColor);
  1143.                DrawLine(oldx,oldy,pCursor.x,pCursor.y,1,CurrentColor);
  1144.                break;
  1145.           case RECTANGLE:
  1146.           case SCISSORS:
  1147.           case FLIPV:
  1148.                   case FLIPH:
  1149.                   case FILLEDRECTANGLE:
  1150.                hdc = GetDC(hWnd);
  1151.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1152.                RealizePalette(hdc);
  1153.                SetROP2(hdc,R2_XORPEN);
  1154.                hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1155.                hop = SelectObject(hdc,hOurPen);
  1156.                Box(hdc,oldx,oldy,xwas,ywas);
  1157.                Box(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1158.                xwas = pCursor.x;
  1159.                ywas = pCursor.y;
  1160.                SelectPalette(hdc, oldpal, FALSE);
  1161.                SelectObject(hdc,hop);
  1162.                ReleaseDC(hWnd,hdc);
  1163.                DeleteObject(hOurPen);
  1164.                break;
  1165.           case CIRCLE:
  1166.           case FILLEDCIRCLE:
  1167.                hdc = GetDC(hWnd);
  1168.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1169.                RealizePalette(hdc);
  1170.                SetROP2(hdc,R2_XORPEN);
  1171.                hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1172.                logbrush.lbStyle = BS_HOLLOW;
  1173.                hBrush = CreateBrushIndirect(&logbrush);
  1174.                hobr = SelectObject(hdc,hBrush);
  1175.                hop = SelectObject(hdc,hOurPen);
  1176.                Ellipse(hdc,oldx,oldy,xwas,ywas);
  1177.                Ellipse(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1178.                xwas = pCursor.x;
  1179.                ywas = pCursor.y;
  1180.                SelectPalette(hdc, oldpal, FALSE);
  1181.                SelectObject(hdc,hop);
  1182.                SelectObject(hdc,hobr);
  1183.                ReleaseDC(hWnd,hdc);
  1184.                DeleteObject(hOurPen);
  1185.                        DeleteObject(hBrush);
  1186.                break;
  1187.           case ZIGZAG:
  1188.                if(pCursor.x > oldx)
  1189.               halfx = ((pCursor.x - oldx) / 2) + oldx;
  1190.                else
  1191.               halfx = ((oldx - pCursor.x) / 2) + pCursor.x;
  1192.                j = random(DrawWidth * 3);
  1193.                if(j%2 != 0) j *= -1;
  1194.                DrawLine(oldx,oldy,halfx,pCursor.y + j,DrawWidth,CurrentColor);
  1195.                DrawLine(halfx, pCursor.y + j, pCursor.x, pCursor.y,DrawWidth,CurrentColor);
  1196.                oldx = pCursor.x;
  1197.                    oldy = pCursor.y;
  1198.                        break;
  1199.           case TRIANGLE:
  1200.                   case FILLEDTRIANGLE:
  1201.                hdc = GetDC(hWnd);
  1202.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1203.                RealizePalette(hdc);
  1204.                SetROP2(hdc,R2_XORPEN);
  1205.                hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1206.                hop = SelectObject(hdc,hOurPen);
  1207.                        // old triangle
  1208.                if(oldx > xwas)
  1209.               halfx = ((oldx - xwas) / 2) + xwas;
  1210.                else
  1211.               halfx = ((xwas - oldx) / 2) + oldx;
  1212.                Line(hdc,oldx,ywas,xwas,ywas);
  1213.                Line(hdc,oldx, ywas, halfx, oldy);
  1214.                Line(hdc,halfx,oldy,xwas,ywas);
  1215.                        // new one
  1216.                if(pCursor.x > oldx)
  1217.               halfx = ((pCursor.x - oldx) / 2) + oldx;
  1218.                else
  1219.               halfx = ((oldx - pCursor.x) / 2) + pCursor.x;
  1220.                Line(hdc,oldx,pCursor.y,pCursor.x,pCursor.y);
  1221.                Line(hdc,oldx, pCursor.y, halfx, oldy);
  1222.                Line(hdc,halfx,oldy,pCursor.x,pCursor.y);
  1223.                SelectPalette(hdc, oldpal, FALSE);
  1224.                SelectObject(hdc,hop);
  1225.                xwas = pCursor.x;
  1226.                    ywas = pCursor.y;
  1227.                ReleaseDC(hWnd,hdc);
  1228.                DeleteObject(hOurPen);
  1229.                break;
  1230.         } // switch DrawTool
  1231.             } // if buttondown
  1232.         break;
  1233.        case WM_LBUTTONUP:
  1234.         buttondown = FALSE;
  1235.         ReleaseCapture();
  1236.         switch(DrawTool){
  1237.            case SPRAYCAN:
  1238.             sndPlaySound("spray2.wav",SND_ASYNC);
  1239.                     break;
  1240.            case LINE:
  1241.                     PlaySound(16);
  1242.             pCursor = MAKEPOINT(lParam);
  1243.             hdc = GetDC(hWnd);
  1244.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1245.             RealizePalette(hdc);
  1246.             SetROP2(hdc,R2_XORPEN);
  1247.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1248.             hPen1 = CreatePen(PS_SOLID,DrawWidth,CurrentColor | 0x2000000L);
  1249.             hop = SelectObject(hdc,hOurPen);
  1250.             Line(hdc,oldx,oldy,xwas,ywas);
  1251.             SelectObject(hdc,hop);
  1252.             hop = SelectObject(hdc,hPen1);
  1253.             SetROP2(hdc,R2_COPYPEN);
  1254.             Line(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1255.             SelectPalette(hdc, oldpal, FALSE);
  1256.             SelectObject(hdc,hop);
  1257.             ReleaseDC(hWnd,hdc);
  1258.             DeleteObject(hOurPen);
  1259.             DeleteObject(hPen1);
  1260.             break;
  1261.            case RECTANGLE:
  1262.             PlaySound(21);
  1263.             pCursor = MAKEPOINT(lParam);
  1264.             hdc = GetDC(hWnd);
  1265.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1266.             RealizePalette(hdc);
  1267.             SetROP2(hdc,R2_XORPEN);
  1268.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1269.             hPen1 = CreatePen(PS_SOLID,DrawWidth,CurrentColor | 0x2000000L);
  1270.             hop = SelectObject(hdc,hOurPen);
  1271.             Box(hdc,oldx,oldy,xwas,ywas);
  1272.             SelectObject(hdc,hop);
  1273.             hop = SelectObject(hdc,hPen1);
  1274.             SetROP2(hdc,R2_COPYPEN);
  1275.             Box(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1276.             SelectPalette(hdc, oldpal, FALSE);
  1277.             SelectObject(hdc,hop);
  1278.             ReleaseDC(hWnd,hdc);
  1279.             DeleteObject(hOurPen);
  1280.             DeleteObject(hPen1);
  1281.             break;
  1282.            case SCISSORS:
  1283.             pCursor = MAKEPOINT(lParam);
  1284.             hdc = GetDC(hWnd);
  1285.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1286.             RealizePalette(hdc);
  1287.             SetROP2(hdc,R2_XORPEN);
  1288.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1289.             hPen1 = CreatePen(PS_SOLID,DrawWidth,WHITE);
  1290.             hop = SelectObject(hdc,hOurPen);
  1291.             Box(hdc,oldx,oldy,xwas,ywas);
  1292.             SelectObject(hdc,hop);
  1293.             hop = SelectObject(hdc,hPen1);
  1294.             SetROP2(hdc,R2_COPYPEN);
  1295.             hBrush = CreateSolidBrush(WHITE);
  1296.             hobr = SelectObject(hdc, hBrush);
  1297.             Rectangle(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1298.             SelectObject(hdc,hop);
  1299.             SelectObject(hdc,hobr);
  1300.             SelectPalette(hdc, oldpal, FALSE);
  1301.             ReleaseDC(hWnd,hdc);
  1302.             DeleteObject(hOurPen);
  1303.             DeleteObject(hPen1);
  1304.             DeleteObject(hBrush);
  1305.             break;
  1306.            case FLIPH:
  1307.             PlaySound(74);
  1308.             pCursor = MAKEPOINT(lParam);
  1309.             hdc = GetDC(hWnd);
  1310.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1311.             RealizePalette(hdc);
  1312.             SetROP2(hdc,R2_XORPEN);
  1313.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1314.             hop = SelectObject(hdc,hOurPen);
  1315.             Box(hdc,oldx,oldy,xwas,ywas);
  1316.             SetROP2(hdc,R2_COPYPEN);
  1317.             x = pCursor.x - oldx;
  1318.             y = pCursor.y - oldy;
  1319.             StretchBlt(hdc,oldx,oldy,x,y, hdc, oldx + x, oldy, x * -1,y,SRCCOPY);
  1320.             SelectObject(hdc,hop);
  1321.             SelectPalette(hdc, oldpal, FALSE);
  1322.             ReleaseDC(hWnd,hdc);
  1323.             DeleteObject(hOurPen);
  1324.             break;
  1325.            case FLIPV:
  1326.             PlaySound(75);
  1327.             pCursor = MAKEPOINT(lParam);
  1328.             hdc = GetDC(hWnd);
  1329.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1330.             RealizePalette(hdc);
  1331.             SetROP2(hdc,R2_XORPEN);
  1332.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1333.             hop = SelectObject(hdc,hOurPen);
  1334.             Box(hdc,oldx,oldy,xwas,ywas);
  1335.             SetROP2(hdc,R2_COPYPEN);
  1336.             x = pCursor.x - oldx;
  1337.             y = pCursor.y - oldy;
  1338.             StretchBlt(hdc,oldx,oldy,x, y, hdc, oldx, oldy + y, x, y * -1,SRCCOPY);
  1339.             SelectObject(hdc,hop);
  1340.             SelectPalette(hdc, oldpal, FALSE);
  1341.             ReleaseDC(hWnd,hdc);
  1342.             DeleteObject(hOurPen);
  1343.             break;
  1344.            case CIRCLE:
  1345.             PlaySound(27);
  1346.             pCursor = MAKEPOINT(lParam);
  1347.             hdc = GetDC(hWnd);
  1348.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1349.             RealizePalette(hdc);
  1350.             SetROP2(hdc,R2_XORPEN);
  1351.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1352.             hPen1 = CreatePen(PS_SOLID,DrawWidth,CurrentColor | 0x2000000L);
  1353.             hop = SelectObject(hdc,hOurPen);
  1354.             logbrush.lbStyle = BS_HOLLOW;
  1355.             hBrush = CreateBrushIndirect(&logbrush);
  1356.             hobr = SelectObject(hdc,hBrush);
  1357.             Ellipse(hdc,oldx,oldy,xwas,ywas);
  1358.             SelectObject(hdc,hop);
  1359.             hop = SelectObject(hdc,hPen1);
  1360.             SetROP2(hdc,R2_COPYPEN);
  1361.             Ellipse(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1362.             SelectObject(hdc,hop);
  1363.             SelectObject(hdc,hobr);
  1364.             SelectPalette(hdc, oldpal, FALSE);
  1365.             ReleaseDC(hWnd,hdc);
  1366.             DeleteObject(hOurPen);
  1367.             DeleteObject(hPen1);
  1368.                     DeleteObject(hBrush);
  1369.             break;
  1370.            case FILLEDRECTANGLE:
  1371.             PlaySound(22);
  1372.             pCursor = MAKEPOINT(lParam);
  1373.             hdc = GetDC(hWnd);
  1374.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1375.             RealizePalette(hdc);
  1376.             SetROP2(hdc,R2_XORPEN);
  1377.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1378.             hPen1 = CreatePen(PS_SOLID,1,CurrentColor | 0x2000000L);
  1379.             hop = SelectObject(hdc,hOurPen);
  1380.             Box(hdc,oldx,oldy,xwas,ywas);
  1381.             SelectObject(hdc,hop);
  1382.             hop = SelectObject(hdc,hPen1);
  1383.             SetROP2(hdc,R2_COPYPEN);
  1384.             hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  1385.             hobr = SelectObject(hdc, hBrush);
  1386.             Rectangle(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1387.             SelectObject(hdc,hop);
  1388.             SelectObject(hdc,hobr);
  1389.             SelectPalette(hdc, oldpal, FALSE);
  1390.             ReleaseDC(hWnd,hdc);
  1391.             DeleteObject(hOurPen);
  1392.             DeleteObject(hPen1);
  1393.             DeleteObject(hBrush);
  1394.             break;
  1395.            case FILLEDCIRCLE:
  1396.             PlaySound(28);
  1397.             pCursor = MAKEPOINT(lParam);
  1398.             hdc = GetDC(hWnd);
  1399.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1400.             RealizePalette(hdc);
  1401.             SetROP2(hdc,R2_XORPEN);
  1402.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1403.             hPen1 = CreatePen(PS_SOLID,1,CurrentColor | 0x2000000L);
  1404.             hop = SelectObject(hdc,hOurPen);
  1405.             logbrush.lbStyle = BS_HOLLOW;
  1406.             hBrush = CreateBrushIndirect(&logbrush);
  1407.             hobr = SelectObject(hdc,hBrush);
  1408.             Ellipse(hdc,oldx,oldy,xwas,ywas);
  1409.             SelectObject(hdc,hop);
  1410.             SelectObject(hdc,hobr);
  1411.             hop = SelectObject(hdc,hPen1);
  1412.             SetROP2(hdc,R2_COPYPEN);
  1413.             hBrush1 = CreateSolidBrush(CurrentColor | 0x2000000L);
  1414.                     hobr = SelectObject(hdc, hBrush1);
  1415.             Ellipse(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1416.             SelectObject(hdc,hop);
  1417.             SelectObject(hdc,hobr);
  1418.             SelectPalette(hdc, oldpal, FALSE);
  1419.             ReleaseDC(hWnd,hdc);
  1420.             DeleteObject(hOurPen);
  1421.             DeleteObject(hPen1);
  1422.             DeleteObject(hBrush);
  1423.             DeleteObject(hBrush1);
  1424.             break;
  1425.            case TRIANGLE:
  1426.             PlaySound(16);
  1427.             pCursor = MAKEPOINT(lParam);
  1428.             hdc = GetDC(hWnd);
  1429.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1430.             RealizePalette(hdc);
  1431.             SetROP2(hdc,R2_XORPEN);
  1432.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1433.             hop = SelectObject(hdc,hOurPen);
  1434.                     // old triangle
  1435.             if(oldx > xwas)
  1436.                halfx = ((oldx - xwas) / 2) + xwas;
  1437.             else
  1438.                halfx = ((xwas - oldx) / 2) + oldx;
  1439.             Line(hdc,oldx,ywas,xwas,ywas);
  1440.             Line(hdc,oldx, ywas, halfx, oldy);
  1441.             Line(hdc,halfx,oldy,xwas,ywas);
  1442.             SelectObject(hdc,hop);
  1443.  
  1444.                     // new one
  1445.             if(pCursor.x > oldx)
  1446.                halfx = ((pCursor.x - oldx) / 2) + oldx;
  1447.             else
  1448.                halfx = ((oldx - pCursor.x) / 2) + pCursor.x;
  1449.             SetROP2(hdc,R2_COPYPEN);
  1450.             hPen1 = CreatePen(PS_SOLID,DrawWidth,CurrentColor | 0x2000000L);
  1451.             hop = SelectObject(hdc,hPen1);
  1452.             Line(hdc,oldx,pCursor.y,pCursor.x,pCursor.y);
  1453.             Line(hdc,oldx, pCursor.y, halfx, oldy);
  1454.             Line(hdc,halfx,oldy,pCursor.x,pCursor.y);
  1455.             SelectObject(hdc,hop);
  1456.             SelectPalette(hdc, oldpal, FALSE);
  1457.             ReleaseDC(hWnd,hdc);
  1458.             DeleteObject(hOurPen);
  1459.             DeleteObject(hPen1);
  1460.             break;
  1461.            case FILLEDTRIANGLE:
  1462.             PlaySound(94);
  1463.             pCursor = MAKEPOINT(lParam);
  1464.             hdc = GetDC(hWnd);
  1465.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1466.             RealizePalette(hdc);
  1467.             SetROP2(hdc,R2_XORPEN);
  1468.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1469.             hop = SelectObject(hdc,hOurPen);
  1470.                     // old triangle
  1471.             if(oldx > xwas)
  1472.                halfx = ((oldx - xwas) / 2) + xwas;
  1473.             else
  1474.                halfx = ((xwas - oldx) / 2) + oldx;
  1475.             Line(hdc,oldx,ywas,xwas,ywas);
  1476.             Line(hdc,oldx, ywas, halfx, oldy);
  1477.             Line(hdc,halfx,oldy,xwas,ywas);
  1478.                     // new one
  1479.             if(pCursor.x > oldx)
  1480.                halfx = ((pCursor.x - oldx) / 2) + oldx;
  1481.             else
  1482.                halfx = ((oldx - pCursor.x) / 2) + pCursor.x;
  1483.             SetROP2(hdc,R2_COPYPEN);
  1484.             SelectObject(hdc,hop);
  1485.             hPen1 = CreatePen(PS_SOLID,DrawWidth,CurrentColor | 0x2000000L);
  1486.             hop = SelectObject(hdc,hPen1);
  1487.             polypoint[0].x = oldx;
  1488.             polypoint[0].y = pCursor.y;
  1489.             polypoint[1].x = halfx;
  1490.             polypoint[1].y = oldy;
  1491.             polypoint[2].x = pCursor.x;
  1492.             polypoint[2].y = pCursor.y;
  1493.             polypoint[3].x = oldx;
  1494.             polypoint[3].y = pCursor.y;
  1495.             hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  1496.                     hobr = SelectObject(hdc, hBrush);
  1497.             Polygon(hdc,polypoint,4);
  1498.             SelectObject(hdc,hop);
  1499.             SelectObject(hdc,hobr);
  1500.             SelectPalette(hdc, oldpal, FALSE);
  1501.             ReleaseDC(hWnd,hdc);
  1502.             DeleteObject(hOurPen);
  1503.             DeleteObject(hPen1);
  1504.             DeleteObject(hBrush);
  1505.             break;
  1506.            case SMALLERASER:
  1507.             hdc = GetDC(hWnd);
  1508.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1509.             RealizePalette(hdc);
  1510.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1511.             x = oldx - 10;
  1512.             y = oldy - 10;
  1513.             hop = SelectObject(hdc,hOurPen);
  1514.             Box(hdc,x,y,x+20,y+20);
  1515.             SelectObject(hdc,hop);
  1516.             SelectPalette(hdc, oldpal, FALSE);
  1517.             ReleaseDC(hWnd,hdc);
  1518.             DeleteObject(hOurPen);
  1519.             break;
  1520.            case LARGEERASER:
  1521.             hdc = GetDC(hWnd);
  1522.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1523.             RealizePalette(hdc);
  1524.             hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1525.             x = oldx - 20;
  1526.             y = oldy - 20;
  1527.             hop = SelectObject(hdc,hOurPen);
  1528.             Box(hdc,x,y,x+40,y+40);
  1529.             SelectObject(hdc,hop);
  1530.             SelectPalette(hdc, oldpal, FALSE);
  1531.             ReleaseDC(hWnd,hdc);
  1532.             DeleteObject(hOurPen);
  1533.             break;
  1534.            case MULTIPOLY:
  1535.             PlaySound(59);
  1536.             pCursor = MAKEPOINT(lParam);
  1537.             hdc = GetDC(hWnd);
  1538.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1539.             RealizePalette(hdc);
  1540.             hOurPen = CreatePen(PS_SOLID,1,CurrentColor | 0x2000000L);
  1541.             hop = SelectObject(hdc,hOurPen);
  1542.             Line(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1543.                 oldx = pCursor.x;
  1544.             oldy = pCursor.y;
  1545.             polypoint[polycount].x = oldx;
  1546.             polypoint[polycount].y = oldy;
  1547.             hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  1548.                     hobr = SelectObject(hdc, hBrush);
  1549.             Polygon(hdc,polypoint,polycount);
  1550.             SelectObject(hdc,hop);
  1551.             SelectObject(hdc,hobr);
  1552.             SelectPalette(hdc, oldpal, FALSE);
  1553.             ReleaseDC(hWnd,hdc);
  1554.             DeleteObject(hOurPen);
  1555.             DeleteObject(hBrush);
  1556.             break;
  1557.            case KNIFE:
  1558.             pCursor = MAKEPOINT(lParam);
  1559.             hdc = GetDC(hWnd);
  1560.             oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1561.             RealizePalette(hdc);
  1562.                 hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1563.             hop = SelectObject(hdc,hOurPen);
  1564.             Line(hdc,oldx,oldy,pCursor.x,pCursor.y);
  1565.                 oldx = pCursor.x;
  1566.             oldy = pCursor.y;
  1567.             polypoint[polycount].x = oldx;
  1568.             polypoint[polycount].y = oldy;
  1569.             hBrush = CreateSolidBrush(WHITE);
  1570.                     hobr = SelectObject(hdc, hBrush);
  1571.             Polygon(hdc,polypoint,polycount);
  1572.             SelectObject(hdc,hop);
  1573.             SelectObject(hdc,hobr);
  1574.             SelectPalette(hdc, oldpal, FALSE);
  1575.             ReleaseDC(hWnd,hdc);
  1576.             DeleteObject(hOurPen);
  1577.             DeleteObject(hBrush);
  1578.             break;
  1579.         }
  1580.         break;
  1581.       default:
  1582.        return(DefWindowProc(hWnd, message, wParam, lParam));
  1583.    }
  1584.    return(0L);
  1585. }
  1586.  
  1587.  
  1588. void ColorAssign(void)
  1589. {
  1590.      aColor[0] = RED2;
  1591.      aColor[1] = RED;
  1592.      aColor[2] = RED1;
  1593.      aColor[3] = DKRED;
  1594.      aColor[4] = BLUE; 
  1595.      aColor[5] = BLUE1;
  1596.      aColor[6] = DKBLUE;
  1597.      aColor[7] = GREEN;
  1598.      aColor[8] = GREEN1;
  1599.      aColor[9] = DKGREEN;
  1600.      aColor[10] = CYAN;
  1601.      aColor[11] = CYAN1;
  1602.      aColor[12] = DKCYAN;
  1603.      aColor[13] = MAGENTA;
  1604.      aColor[14] = MAGENTA1;
  1605.      aColor[15] = DKMAGENTA;
  1606.      aColor[16] = YELLOW;
  1607.      aColor[17] = YELLOW1;
  1608.      aColor[18] = DKYELLOW;
  1609.      aColor[19] = WHITE;
  1610.      aColor[20] = GRAY;
  1611.      aColor[21] = DKGRAY;
  1612.      aColor[22] = BLACK;
  1613.      aColor[23] = BROWN;
  1614.      aColor[24] = BROWN1;
  1615.      aColor[25] = DKBROWN;
  1616.      aColor[26] = TURQUOISE;
  1617.      aColor[27] = TURQUOISE1;
  1618.      aColor[28] = DKTURQUOISE;
  1619.      aColor[29] = ORANGE;
  1620.      aColor[30] = ORANGE1;
  1621.      aColor[31] = DKORANGE;
  1622.      aColor[32] = ORANGE2;
  1623. }
  1624.  
  1625. //*******************************************************************
  1626. //                handles messages for this application
  1627. //*******************************************************************
  1628. LRESULT CALLBACK PaintWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  1629. {
  1630.     HDC              hdc;
  1631.     RECT             rct;
  1632.     DWORD            res;
  1633.     WORD             wDeviceID;
  1634.     POINT            pCursor;
  1635.     HBRUSH           hBrush, hobr;
  1636.     WNDCLASS         secondclass;
  1637.     int              i,j;
  1638.     static HWND      hwnd1, hwnd2, hwnd3, hwnd4, hwnd5, hwnd6, hwnd7;
  1639.     char             buf[20], savethreshtext[80], cindrive, coutdrive;
  1640.     unsigned char    c;
  1641.     PLOGPALETTE      plp;
  1642.     LOCALHANDLE      lh;
  1643.     HPALETTE         oldpal;
  1644.     HPEN             hop;
  1645.     static HICON     hIcon1, hIcon2, hIcon3, hIcon4, hIcon5, hIcon6, hIcon7;
  1646.  
  1647.  
  1648.     switch (message){
  1649.     case WM_CREATE:
  1650.          ColorAssign();
  1651.          lh = LocalAlloc(LMEM_MOVEABLE,sizeof(LOGPALETTE) * 33 * sizeof(PALETTEENTRY));
  1652.          plp = (PLOGPALETTE)LocalLock(lh);
  1653.          plp->palVersion = 0x300;
  1654.          plp->palNumEntries = 33;
  1655.          for(i = 0; i < 33; i++){
  1656.          plp->palPalEntry[i].peRed = GetRValue(aColor[i]);
  1657.          plp->palPalEntry[i].peGreen = GetGValue(aColor[i]);
  1658.          plp->palPalEntry[i].peBlue =  GetBValue(aColor[i]);
  1659.          plp->palPalEntry[i].peFlags = 0;
  1660.          }
  1661.          hwndpal = CreatePalette(plp);
  1662.          LocalUnlock(lh);
  1663.          LocalFree(lh);
  1664.  
  1665.              savelevel = 6000000L;      // default to 6 megs
  1666.  
  1667.          // look for the INI file showing us where we'll be
  1668.          // working from. The install program will need to be
  1669.              // smart enough to set this up...
  1670.          GetPrivateProfileString("PAINT","directoryin","n",ourdir,80,"KA.INI");
  1671.          GetPrivateProfileString("PAINT","directoryout","n",outdir,80,"KA.INI");
  1672.          GetPrivateProfileString("PAINT","savethreshold","n",savethreshtext,80,"KA.INI");
  1673.          // Determine the minimum amount of memory one must have to
  1674.          // legally save a picture. We let K.A. determine their optimum
  1675.          // setting via the INI file and follow this. Their value
  1676.          // will be an integer that represents 'K'.  
  1677.          savelevel = atol(savethreshtext) * 1024;
  1678.          cindrive = toupper(ourdir[0]);
  1679.          coutdrive = toupper(outdir[0]);
  1680.  
  1681.          indrive = cindrive - 65;
  1682.              outdrive = coutdrive - 65;
  1683.  
  1684.          i = lstrlen(ourdir);
  1685.          // ...but never trust ANYONE. If the install screwed up, we have
  1686.              // to figure out where we were launched from.
  1687.          if(i < 2) FindOurDirectory();
  1688.  
  1689.              // the CLOSE button ALWAYS gets drawn.
  1690.          hwnd1 = CreateWindow ("button", "&Close",
  1691.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1692.                hres - 66, 0, 66, 50,
  1693.                hWnd, (HMENU)IDBT_CLEAR, hInst, NULL);
  1694.  
  1695.          if(colorbook == FALSE){
  1696.                 // these get drawn when not in colorbook mode
  1697.             hwnd2 = CreateWindow ("button", "Draw",
  1698.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1699.                0, 180, 50, 50,
  1700.                hWnd, (HMENU)IDBT_SNDPLAY, hInst, NULL);
  1701.  
  1702.             hwnd3 = CreateWindow ("button", "Erase",
  1703.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1704.                0, 230, 50, 50,
  1705.                        hWnd, (HMENU)IDBT_MCICMD, hInst, NULL);
  1706.  
  1707.             hwnd4 = CreateWindow ("button", "F/X",
  1708.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1709.                0, 280, 50, 50,
  1710.                hWnd, (HMENU)IDBT_MCISTR, hInst, NULL);
  1711.  
  1712.             hwnd5 = CreateWindow ("button", "Text",
  1713.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1714.                0, 330, 50, 50,
  1715.                hWnd, (HMENU)IDBT_TEXT, hInst, NULL);
  1716.  
  1717.             hwnd6 = CreateWindow ("button", "Misc.",
  1718.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1719.                0, 380, 50, 50,
  1720.                hWnd, (HMENU)IDBT_STAMP, hInst, NULL);
  1721.  
  1722.             hwnd7 = CreateWindow ("button", "Stamps",
  1723.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1724.                0, 430, 50, 50,
  1725.                hWnd, (HMENU)IDBT_MISC, hInst, NULL);
  1726.  
  1727.         if(hres < 680){
  1728.            j = 33;
  1729.                 }
  1730.         else{
  1731.                    j = 66;
  1732.         }
  1733.         hwnd8 = CreateWindow ("button", "undo",
  1734.                WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON | BS_OWNERDRAW,
  1735.                541, 0, j, 50,
  1736.                hWnd, (HMENU)IDBT_UNDO, hInst, NULL);
  1737.  
  1738.  
  1739.                  hIcon1 = LoadIcon(hInst,"ICON_42");
  1740.                 hIcon2 = LoadIcon(hInst,"ICON_43");
  1741.                 hIcon3 = LoadIcon(hInst,"ICON_44");
  1742.                 hIcon4 = LoadIcon(hInst,"ICON_45");
  1743.                 hIcon5 = LoadIcon(hInst,"ICON_46");
  1744.         hIcon6 = LoadIcon(hInst,"ICON_47");
  1745.         hIcon7 = LoadIcon(hInst,"ICON_125");
  1746.          }
  1747.  
  1748.          // choose the return button image shown to the user
  1749.  
  1750.          switch(kabitmapID){
  1751.         case 1:
  1752.              kabitmap = LoadBitmap(hInst,"BITMAP_1");
  1753.              break;
  1754.         case 2:
  1755.              kabitmap = LoadBitmap(hInst,"BITMAP_2");
  1756.              break;
  1757.         case 3:
  1758.              kabitmap = LoadBitmap(hInst,"BITMAP_3");
  1759.              break;
  1760.         case 4:
  1761.              kabitmap = LoadBitmap(hInst,"BITMAP_4");
  1762.              break;
  1763.         case 5:
  1764.              kabitmap = LoadBitmap(hInst,"BITMAP_5");
  1765.              break;
  1766.         case 6:
  1767.              kabitmap = LoadBitmap(hInst,"BITMAP_6");
  1768.              break;
  1769.         case 7:
  1770.              kabitmap = LoadBitmap(hInst,"BITMAP_7");
  1771.              break;
  1772.         case 8:
  1773.              kabitmap = LoadBitmap(hInst,"BITMAP_8");
  1774.              break;
  1775.         case 9:
  1776.              kabitmap = LoadBitmap(hInst,"BITMAP_9");
  1777.              break;
  1778.         case 10:
  1779.              kabitmap = LoadBitmap(hInst,"BITMAP_10");
  1780.              break;
  1781.              }
  1782.  
  1783.              // define various variables we'll be using
  1784.          buttondown = FALSE;
  1785.          DrawTool = SPRAYCAN;
  1786.          DrawWidth = 1;
  1787.          numfiles = 1;
  1788.          Thumbnails = FALSE;
  1789.          DoingText = FALSE;
  1790.          ReadyToDoText = FALSE;
  1791.              firstpaint = TRUE;
  1792.          randomize();
  1793.          CurrentColor = RED1;
  1794.          stupidpointer = FALSE;
  1795.              stampsmear = TRUE;
  1796.  
  1797.          // sound resources
  1798.  
  1799.          chthedir(IN);
  1800.          fp=fopen("stamp1.wav","r");
  1801.          fgets(stampwav[0],1500,fp);
  1802.          fclose(fp);
  1803.          fp=fopen("stamp2.wav","r");
  1804.          fgets(stampwav[1],1500,fp);
  1805.          fclose(fp);
  1806.          fp=fopen("stamp3.wav","r");
  1807.          fgets(stampwav[2],1500,fp);
  1808.          fclose(fp);
  1809.          fp=fopen("stamp4.wav","r");
  1810.          fgets(stampwav[3],1500,fp);
  1811.          fclose(fp);
  1812.          fp=fopen("stamp5.wav","r");
  1813.          fgets(stampwav[4],1500,fp);
  1814.          fclose(fp);
  1815.          fp=fopen("stamp6.wav","r");
  1816.          fgets(stampwav[5],1500,fp);
  1817.          fclose(fp);
  1818.          fp=fopen("stamp7.wav","r");
  1819.          fgets(stampwav[6],1500,fp);
  1820.          fclose(fp);
  1821.          fp=fopen("stamp8.wav","r");
  1822.          fgets(stampwav[7],1500,fp);
  1823.          fclose(fp);
  1824.          fp=fopen("spray2.wav","r");
  1825.          fgets(spraywav,1500,fp);
  1826.          fclose(fp);
  1827.  
  1828.              // create the window we actually paint in
  1829.          secondclass.style         = CS_HREDRAW | CS_VREDRAW;
  1830.          secondclass.lpfnWndProc   = PWinProc;
  1831.          secondclass.cbClsExtra    = 0;
  1832.              secondclass.cbWndExtra    = 0;
  1833.              secondclass.hInstance     = hInst;
  1834.          secondclass.hIcon         = NULL;
  1835.              secondclass.hCursor       = LoadCursor(hInst,IDC_ARROW);
  1836.          secondclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  1837.              secondclass.lpszClassName = "secondclass";
  1838.          secondclass.lpszMenuName  = NULL;
  1839.  
  1840.          RegisterClass(&secondclass);
  1841.  
  1842.          phwnd = CreateWindow("secondclass",    // window class name
  1843.                         "title",                       //  window title
  1844.             WS_BORDER | WS_CHILD | WS_VISIBLE,
  1845.             50,                      // upper left x
  1846.             50,                      // upper left y
  1847.             hres - 50,                    // width
  1848.             vres - 50,                    // height
  1849.             hWnd,               // parent for this window
  1850.             NULL,                   // use the class menu
  1851.             hInst,             // who created this window
  1852.                         NULL                    // no parms to pass on
  1853.             );
  1854.          ShowWindow(phwnd, SW_SHOW);
  1855.  
  1856.          return(DefWindowProc(hWnd, message, wParam, lParam));
  1857.  
  1858.     case WM_DRAWITEM:
  1859.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_SNDPLAY)
  1860.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon1);
  1861.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_MCICMD)
  1862.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon2);
  1863.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_MCISTR)
  1864.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon3);
  1865.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_TEXT)
  1866.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon4);
  1867.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_STAMP)
  1868.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon5);
  1869.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_MISC)
  1870.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon6);
  1871.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_CLEAR)
  1872.           WndDrawBitmapButton((LPDRAWITEMSTRUCT)lParam,kabitmap);
  1873.          if(((LPDRAWITEMSTRUCT)lParam)->CtlID == IDBT_UNDO)
  1874.           WndDrawIconButton((LPDRAWITEMSTRUCT)lParam,hIcon7);
  1875.              Thumbnails = FALSE;
  1876.          break;
  1877.         case WM_CHAR:
  1878.                  if(DoingText == TRUE){
  1879.             c = wParam;
  1880.             if(c > 96 && c < 123) c -= 32;    // make sure it's a capital letter,
  1881.                        // per Amory Gabel 9/14/94
  1882.             if((c > 31 && c < 127) || c == 13 || c == 8)
  1883.                ShowText(c);
  1884.          }
  1885.          break;
  1886.         case WM_COMMAND:
  1887.          if(DoingText == TRUE) cleanuptext();
  1888.          ReadyToDoText = FALSE;
  1889.          if(colorbook == FALSE) ShowWindow(hwnd8,SW_SHOWNA);
  1890.              switch (wParam){
  1891.               case IDBT_CLEAR:
  1892.                PlaySound(42);
  1893.                            if(colorbook == FALSE){
  1894.                   DestroyIcon(hIcon7);
  1895.                   DestroyIcon(hIcon6);
  1896.                   DestroyIcon(hIcon5);
  1897.                   DestroyIcon(hIcon4);
  1898.                   DestroyIcon(hIcon3);
  1899.                   DestroyIcon(hIcon2);
  1900.                   DestroyIcon(hIcon1);
  1901.                            }
  1902.                DestroyWindow(hWnd);
  1903.                    break;
  1904.               case IDBT_SNDPLAY:
  1905.                DrawTools1();
  1906.                SaveToUndoPic();
  1907.                    break;
  1908.               case IDBT_MCISTR:
  1909.                DrawTools5();
  1910.                SaveToUndoPic();
  1911.                    break;
  1912.               case IDBT_MCICMD:
  1913.                DrawTools4();
  1914.                SaveToUndoPic();
  1915.                    break;
  1916.               case IDBT_MISC:
  1917.                DrawTools6();
  1918.                            LineSet = FALSE;
  1919.                ShowWindow(hwnd8,SW_HIDE);
  1920.                SaveToUndoPic();
  1921.                break;
  1922.               case IDBT_TEXT:
  1923.                PlaySound(7);
  1924.                            HorizDitherPattern();
  1925.                ReadyToDoText = TRUE;
  1926.                            DrawTool = NONE;
  1927.                SaveToUndoPic();
  1928.                break;
  1929.               case IDBT_STAMP:
  1930.                DrawIcons(random(7) + 7);
  1931.                SaveToUndoPic();
  1932.                break;
  1933.               case IDBT_UNDO:
  1934.                hdc = GetDC(phwnd);
  1935.                oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1936.                RealizePalette(hdc);
  1937.                            PlaySound(2);
  1938.                BitBlt(hdc,0,0,hres-50,vres-50,undodc,0,0,SRCCOPY);
  1939.                            SelectPalette(hdc, oldpal, FALSE);
  1940.                ReleaseDC(phwnd,hdc);
  1941.                            break;
  1942.               default:
  1943.                    break;
  1944.              }
  1945.          break;
  1946.         case WM_PAINT:
  1947.          DoPaint();
  1948.          if(colorbook == FALSE){
  1949.                     if(firstpaint == TRUE){
  1950.                DrawTools1();
  1951.                firstpaint = FALSE;
  1952.             }
  1953.          }
  1954.          else{
  1955.             // If there are more than 5 colorbook pictures,
  1956.             // colorbmpname[5] will have a valid name inside.
  1957.             // In that case, what we want to do is show the
  1958.             // change icon...
  1959.             if(strlen(colorbmpname[5]) < 4)
  1960.                BlankIconArea(0);
  1961.             else
  1962.                BlankIconArea(1);
  1963.             ColorTool(0);
  1964.             DrawTool = COLORBOOK1;
  1965.                     colorset = 1;
  1966.             ColorBookPics(1);
  1967.             LineSet = FALSE;
  1968.          }
  1969.          break;
  1970.         case WM_LBUTTONDOWN:
  1971.          if(DoingText == TRUE){
  1972.             cleanuptext();
  1973.             break;
  1974.          }
  1975.                  if(ReadyToDoText == TRUE){
  1976.             ReadyToDoText = FALSE;
  1977.                     DrawTools1();
  1978.             break;
  1979.          }
  1980.                  // Look for the user to choose a color...
  1981.          pCursor = MAKEPOINT(lParam);
  1982.                  if(colorbook == FALSE){
  1983.                     if((pCursor.x < 50) && (pCursor.y < 160)){
  1984.             hdc = GetDC(hWnd);
  1985.                 oldpal = SelectPalette(hdc, hwndpal, FALSE);
  1986.             RealizePalette(hdc);
  1987.                 CurrentColor = GetPixel(hdc,pCursor.x,pCursor.y) | 0x2000000L;
  1988.                         // and then draw the color picked.
  1989.                 hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  1990.                 hOurPen = CreatePen(PS_SOLID,1,WHITE);
  1991.                         hop = SelectObject(hdc, hOurPen);
  1992.                 hobr = SelectObject(hdc,hBrush);
  1993.             Rectangle(hdc,3,163,47,177);
  1994.             SelectObject(hdc,hop);
  1995.                 SelectObject(hdc,hobr);
  1996.                 SelectPalette(hdc, oldpal, FALSE);
  1997.                 ReleaseDC(hWnd,hdc);
  1998.                 DeleteObject(hBrush);
  1999.             DeleteObject(hOurPen);
  2000.                 SaveToUndoPic();
  2001.                 break;
  2002.             }
  2003.                  }
  2004.          else{
  2005.             if((pCursor.x < 50) && (pCursor.y < 320)){
  2006.                 hdc = GetDC(hWnd);
  2007.                 oldpal = SelectPalette(hdc, hwndpal, FALSE);
  2008.             RealizePalette(hdc);
  2009.                         if(GetPixel(hdc,pCursor.x,pCursor.y) != BLACK){
  2010.                    CurrentColor = GetPixel(hdc,pCursor.x,pCursor.y) | 0x2000000L;
  2011.                            // and then draw the color picked.
  2012.                    hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  2013.                    hOurPen = CreatePen(PS_SOLID,1,WHITE);
  2014.                            hop = SelectObject(hdc, hOurPen);
  2015.                    hobr = SelectObject(hdc,hBrush);
  2016.                Rectangle(hdc,3,323,47,337);
  2017.             }
  2018.             SelectObject(hdc,hop);
  2019.                 SelectObject(hdc,hobr);
  2020.             SelectPalette(hdc, oldpal, FALSE);
  2021.                 ReleaseDC(hWnd,hdc);
  2022.             DeleteObject(hBrush);
  2023.                         DeleteObject(hOurPen);
  2024.                 SaveToUndoPic();
  2025.                 break;
  2026.             }
  2027.          }
  2028.          if(colorbook == TRUE){
  2029.             if(pCursor.y > 5 && pCursor.y < 40){
  2030.                if(pCursor.x > 60 && pCursor.x < 120){
  2031.               ColorBookPicked(0);
  2032.                   break;
  2033.                }
  2034.                if(pCursor.x > 140 && pCursor.x < 200){
  2035.               ColorBookPicked(1);
  2036.                   break;
  2037.                }
  2038.                if(pCursor.x > 220 && pCursor.x < 280){
  2039.               ColorBookPicked(2);
  2040.                   break;
  2041.                }
  2042.                if(pCursor.x > 300 && pCursor.x < 360){
  2043.               ColorBookPicked(3);
  2044.               break;
  2045.                }
  2046.                if(pCursor.x > 380 && pCursor.x < 440){
  2047.               ColorBookPicked(4);
  2048.                   break;
  2049.                }
  2050.             } // if pCursor.y
  2051.             if(pCursor.x > 5 && pCursor.x < 45){
  2052.                if(pCursor.y > 340 && pCursor.y < 380){
  2053.               ColorTool(0);
  2054.               break;
  2055.                }
  2056.                if(pCursor.y > 380 && pCursor.y < 420){
  2057.               ColorTool(1);
  2058.               break;
  2059.                        }
  2060.             }
  2061.             if(pCursor.x > 475 && pCursor.x <= 515 &&
  2062.                pCursor.y > 5 && pCursor.y < 45){
  2063.                if(strlen(colorbmpname[5]) > 4){
  2064.               BlankIconArea(1);
  2065.               if(colorset == 1){
  2066.                  ColorBookPics(2);
  2067.                  colorset = 2;
  2068.                  break;
  2069.               }
  2070.               else{
  2071.  
  2072.                  ColorBookPics(1);
  2073.                  colorset = 1;
  2074.                  break;
  2075.                           }
  2076.                }
  2077.             }
  2078.             // allow color books to print...
  2079.             if(pCursor.x > 540 && pCursor.x < 580 &&
  2080.                pCursor.y > 10 && pCursor.y < 40){
  2081.                PrintIt();
  2082.                break;
  2083.             }
  2084.                     break;
  2085.          } // if colorbook = true
  2086.                  if(Thumbnails == FALSE){
  2087.                     // look for a tool to be chosen
  2088.             for(i = 58, j = 1; i < 341; i += 40, j++){
  2089.                 if(pCursor.x >= i && pCursor.x < i + 36 &&
  2090.                    pCursor.y >= 8 && pCursor.y < 44){
  2091.                if(ToolSet == 1 || ToolSet == 2 ||
  2092.                   ToolSet == 3 || ToolSet == 5 || ToolSet > 6)
  2093.                   BoxAroundTool(j);
  2094.                if(ToolSet == 4){
  2095.                   ExecuteErase(j);
  2096.                   break;
  2097.                            }
  2098.                if(ToolSet == 6){
  2099.                   if(j < 6)
  2100.                  ExecuteDisk(j);
  2101.                   else
  2102.                  break;
  2103.                            }
  2104.                            break;
  2105.                 }
  2106.             }
  2107.  
  2108.                     // look to choose a drawing linesize
  2109.                     if(LineSet == TRUE){
  2110.                    for(i = 425, j = 1; i < 535; i += 20, j++){
  2111.                if(pCursor.x >= i && pCursor.x < i + 10 &&
  2112.                   pCursor.y >= 10 && pCursor.y < 41){
  2113.                   DrawWidth = j;
  2114.                   DrawLineSet();
  2115.                   SaveToUndoPic();
  2116.                               memset(buf,20,'\0');                // get the buffer ready
  2117.                   chthedir(IN);
  2118.                               switch(DrawWidth){
  2119.                                    case 1:
  2120.                                    strcpy(buf,"pencil1.wav");
  2121.                                    break;
  2122.                                case 2:
  2123.                                    strcpy(buf,"pencil2.wav");
  2124.                                    break;
  2125.                                case 3:
  2126.                                    strcpy(buf,"pencil3.wav");
  2127.                                    break;
  2128.                                case 4:
  2129.                                    strcpy(buf,"pencil4.wav");
  2130.                                    break;
  2131.                                case 5:
  2132.                                    strcpy(buf,"pencil5.wav");
  2133.                                    break;
  2134.                                case 6:
  2135.                                    strcpy(buf,"pencil6.wav");
  2136.                                    break;
  2137.                               }
  2138.                               sndPlaySound(buf,SND_ASYNC);
  2139.                   break;
  2140.                    }
  2141.                }  // for
  2142.             }
  2143.                     if(ToolSet < 4 || ToolSet > 6){
  2144.                if(pCursor.x > 370 && pCursor.x <= 390 &&
  2145.               pCursor.y > 5 && pCursor.y < 45){
  2146.               PlaySound(101);
  2147.               PreviousToolSet();
  2148.               break;
  2149.                        }
  2150.                if(pCursor.x > 390 && pCursor.x < 410 &&
  2151.               pCursor.y > 5 && pCursor.y < 45){
  2152.               PlaySound(101);
  2153.               NextToolSet();
  2154.               break;
  2155.                }
  2156.             }
  2157.                     SaveToUndoPic();
  2158.                  }
  2159.          else{
  2160.             if(pCursor.y > 5 && pCursor.y < 40){
  2161.                if(pCursor.x > 60 && pCursor.x < 120){
  2162.               UserPickedMe(firstfileshown);
  2163.                   break;
  2164.                }
  2165.                if(pCursor.x > 140 && pCursor.x < 200){
  2166.                   UserPickedMe(firstfileshown + 1);
  2167.                   break;
  2168.                }
  2169.                if(pCursor.x > 220 && pCursor.x < 280){
  2170.                   UserPickedMe(firstfileshown + 2);
  2171.               break;
  2172.                }
  2173.                if(pCursor.x > 300 && pCursor.x < 360){
  2174.                   UserPickedMe(firstfileshown + 3);
  2175.                   break;
  2176.                }
  2177.                if(pCursor.x > 380 && pCursor.x < 440){
  2178.                   UserPickedMe(firstfileshown + 4);
  2179.                   break;
  2180.                }
  2181.                if(pCursor.x > 480 && pCursor.x < 515){
  2182.               MorePicsSelected();
  2183.                   break;
  2184.                }
  2185.                     } // if pCursor.y
  2186.          }
  2187.          break;
  2188.         case WM_SYSCOMMAND:
  2189.          aflag = TRUE;
  2190.          SaveToUndoPic();
  2191.          return(DefWindowProc(hWnd, message, wParam, lParam));
  2192.         case WM_DESTROY:
  2193.          DeleteObject(kabitmap);
  2194.          DeleteObject(hwndpal);
  2195.          PostQuitMessage(0);   // this is the end...
  2196.          break;
  2197.         case WM_SETFOCUS:
  2198.          if(aflag == TRUE){
  2199.             if(colorbook == FALSE)
  2200.                DrawTools1();
  2201.                     else
  2202.                SendMessage(hWnd,WM_PAINT,NULL,NULL);
  2203.                     aflag = FALSE;
  2204.          }
  2205.          break;
  2206.         case WM_CLOSE:
  2207.          // Tell windows to destroy our window.
  2208.          DestroyWindow(hWnd);
  2209.          break;
  2210.         default:
  2211.                 // Let windows handle all messages we choose to ignore.
  2212.          return(DefWindowProc(hWnd, message, wParam, lParam));
  2213.     }
  2214.     return(0L);
  2215. }
  2216.  
  2217. //*************************************************************************
  2218. // DoPaint -- this is the WM_PAINT action routine for the main window.
  2219. //*************************************************************************
  2220.  
  2221. void DoPaint()
  2222. {
  2223.     PAINTSTRUCT       PaintInfo;
  2224.     HDC               hDC;
  2225.     HBRUSH            hBrush, hBrush2, hBrush1[32], hobr;
  2226.     HPEN              hWhite, hpen, hBlack, hop;
  2227.     register int      i;
  2228.     COLORREF          tempcolor;
  2229.     HPALETTE          oldpal;
  2230.     
  2231.  
  2232.     BeginPaint(hWndMain, &PaintInfo);
  2233.     hDC = PaintInfo.hdc;
  2234.     oldpal = SelectPalette(hDC, hwndpal, FALSE);
  2235.     RealizePalette(hDC);
  2236.     hBrush = CreateSolidBrush(CurrentColor | 0x2000000L);
  2237.     hBrush2 = CreateSolidBrush(TURQUOISE1 | 0x2000000L);
  2238.     hobr = SelectObject(hDC,hBrush2);
  2239.     hpen = CreatePen(PS_SOLID,1,TURQUOISE1 | 0x2000000L);
  2240.     hop = SelectObject(hDC,hpen);
  2241.     Rectangle(hDC,0,0,hres,vres);
  2242.     SelectObject(hDC,hop);
  2243.     hBlack = CreatePen(PS_SOLID,1,BLACK);
  2244.     hop = SelectObject(hDC,hBlack);
  2245.     SelectObject(hDC,hobr);
  2246.     // create some brushes to paint the color boxes
  2247.     if(colorbook == FALSE){
  2248.        // AMORY! this is where you get to put in whatever colors you want.
  2249.        hBrush1[0] = CreateSolidBrush(aColor[0] | 0x2000000L);
  2250.        hBrush1[1] = CreateSolidBrush(aColor[2] | 0x2000000L);
  2251.        hBrush1[2] = CreateSolidBrush(aColor[4] | 0x2000000L);
  2252.        hBrush1[3] = CreateSolidBrush(aColor[6] | 0x2000000L);
  2253.        hBrush1[4] = CreateSolidBrush(aColor[8] | 0x2000000L);
  2254.        hBrush1[5] = CreateSolidBrush(aColor[10] | 0x2000000L);
  2255.        hBrush1[6] = CreateSolidBrush(aColor[32] | 0x2000000L);
  2256.        hBrush1[7] = CreateSolidBrush(aColor[14] | 0x2000000L);
  2257.        hBrush1[8] = CreateSolidBrush(aColor[16] | 0x2000000L);
  2258.        hBrush1[9] = CreateSolidBrush(aColor[18] | 0x2000000L);
  2259.        hBrush1[10] = CreateSolidBrush(aColor[20] | 0x2000000L);
  2260.        hBrush1[11] = CreateSolidBrush(aColor[22] | 0x2000000L);
  2261.        hBrush1[12] = CreateSolidBrush(aColor[24] | 0x2000000L);
  2262.        hBrush1[13] = CreateSolidBrush(aColor[26] | 0x2000000L);
  2263.        hBrush1[14] = CreateSolidBrush(aColor[28] | 0x2000000L);
  2264.        hBrush1[15] = CreateSolidBrush(aColor[30] | 0x2000000L);
  2265.        for(i = 0; i <= 7; i++){
  2266.            hobr = SelectObject(hDC,hBrush1[i]);
  2267.        Rectangle(hDC,0,i * 20,25,(i * 20) + 20);
  2268.        SelectObject(hDC,hobr);
  2269.        hobr = SelectObject(hDC,hBrush1[i + 8]);
  2270.        Rectangle(hDC,25,i * 20,50,(i * 20) + 20);
  2271.        SelectObject(hDC,hobr);
  2272.        }
  2273.        // and the current color
  2274.        SelectObject(hDC,hop);
  2275.        hWhite = CreatePen(PS_SOLID,1,WHITE);
  2276.        hop = SelectObject(hDC, hWhite);
  2277.        hobr = SelectObject(hDC,hBrush);
  2278.        Rectangle(hDC,3,163,47,177);
  2279.        SelectObject(hDC,hop);
  2280.        SelectObject(hDC,hobr);
  2281.        SelectPalette(hDC, oldpal, FALSE);
  2282.        EndPaint(hWndMain, &PaintInfo);
  2283.        // and get rid of all the brushes
  2284.        DeleteObject(hBrush);
  2285.        DeleteObject(hBrush2);
  2286.        DeleteObject(hWhite);
  2287.        DeleteObject(hBlack);
  2288.        DeleteObject(hpen);
  2289.        for(i = 0; i < 16; i++) DeleteObject(hBrush1[i]);
  2290.     }
  2291.     else{
  2292.        tempcolor = aColor[22];       // save black
  2293.        aColor[22] = aColor[32];      // substitute orange
  2294.        aColor[32] = tempcolor;       // set 32 == black
  2295.        for(i = 0; i < 32; i++)
  2296.        hBrush1[i] = CreateSolidBrush(aColor[i] | 0x2000000L);
  2297.        // fill the color boxes
  2298.        for(i = 0; i <= 15; i++){
  2299.            hobr = SelectObject(hDC,hBrush1[i]);
  2300.        Rectangle(hDC,0,i * 20,25,(i * 20) + 20);
  2301.        SelectObject(hDC,hobr);
  2302.        hobr = SelectObject(hDC,hBrush1[i + 16]);
  2303.        Rectangle(hDC,25,i * 20,50,(i * 20) + 20);
  2304.        SelectObject(hDC,hobr);
  2305.        }
  2306.        // and the current color
  2307.        SelectObject(hDC,hop);
  2308.        hWhite = CreatePen(PS_SOLID,1,WHITE);
  2309.        hop = SelectObject(hDC, hWhite);
  2310.        hobr = SelectObject(hDC,hBrush);
  2311.        Rectangle(hDC,3,323,47,337);
  2312.        SelectObject(hDC,hop);
  2313.        SelectObject(hDC,hobr);
  2314.        tempcolor = aColor[22];      // save orange
  2315.        aColor[22] = aColor[32];     // restore black
  2316.        aColor[32] = tempcolor;      // and so on...
  2317.        SelectPalette(hDC, oldpal, FALSE);
  2318.        EndPaint(hWndMain, &PaintInfo);
  2319.        // and get rid of all the brushes
  2320.        DeleteObject(hBrush);
  2321.        DeleteObject(hBrush2);
  2322.        DeleteObject(hWhite);
  2323.        DeleteObject(hBlack);
  2324.        DeleteObject(hpen);
  2325.        for(i = 0; i < 32; i++) DeleteObject(hBrush1[i]);
  2326.     }
  2327.     if(firsttime == FALSE){
  2328.         hDC = GetDC(phwnd);
  2329.         oldpal = SelectPalette(hDC, hwndpal, FALSE);
  2330.     RealizePalette(hDC);
  2331.     BitBlt(hDC,0,0,hres-50,vres-50,undodc,0,0,SRCCOPY);
  2332.     SelectPalette(hDC, oldpal, FALSE);
  2333.     ReleaseDC(phwnd, hDC);
  2334.     }
  2335. }
  2336.  
  2337. // Primitive to draw a line
  2338. void Line(HDC hdc, int X1, int Y1, int X2, int Y2)
  2339. {
  2340.      MoveTo(hdc,X1,Y1);
  2341.      LineTo(hdc,X2,Y2);
  2342. }
  2343.  
  2344. // Primitive to draw an unfilled box
  2345. void Box(HDC hdc, int X1, int Y1, int X2, int Y2)
  2346. {
  2347.      Line(hdc, X1,Y1,X2,Y1);
  2348.      Line(hdc, X1,Y1,X1,Y2);
  2349.      Line(hdc, X1,Y2,X2,Y2);
  2350.      Line(hdc, X2,Y1,X2,Y2);
  2351. }
  2352.  
  2353. //*******************************************************************
  2354. // BoxAroundTool -- this routine is responsible for responding to
  2355. // a request to select a new tool. First, we draw a gray box around
  2356. // the currently selected tool. Second, we draw a red box around the
  2357. // tool we wish to use. Third, we determine from the toolset selected
  2358. // what to do, such as changing the drawing tool and so on.
  2359. //********************************************************************
  2360.  
  2361. void BoxAroundTool(int NewBoxPos)
  2362. {
  2363.  
  2364. #define BACKCOLOR      TURQUOISE1
  2365.  
  2366.      HDC               hDC;
  2367.      HPEN              hPen1, hPen2, hop;
  2368.      int               X1;
  2369.      HPALETTE          oldpal;
  2370.  
  2371.      if(NewBoxPos == CurrentBoxPos) return;
  2372.      if(aflag == FALSE) SaveToUndoPic();
  2373.      hDC = GetDC(hWndMain);
  2374.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  2375.      RealizePalette(hDC);
  2376.      hPen1 = CreatePen(PS_SOLID,2,BACKCOLOR | 0x2000000L);
  2377.      hop = SelectObject(hDC,hPen1);
  2378.      // draw a new box around the old tool
  2379.      X1 = ((CurrentBoxPos - 1) * 40) + 58;
  2380.      Box(hDC,X1,8,X1 + 36,44);
  2381.      SelectObject(hDC,hop);
  2382.      hPen2 = CreatePen(PS_SOLID,2,RED | 0x2000000L);
  2383.      hop = SelectObject(hDC,hPen2);
  2384.      // draw a new RED box around the new tool
  2385.      X1 = ((NewBoxPos - 1) * 40) + 58;
  2386.      Box(hDC,X1,8,X1 + 36,44);
  2387.      SelectObject(hDC,hop);
  2388.      // and clean up
  2389.      SelectPalette(hDC, oldpal, FALSE);
  2390.      ReleaseDC(hWndMain,hDC);
  2391.      DeleteObject(hPen1);
  2392.      DeleteObject(hPen2);
  2393.      CurrentBoxPos = NewBoxPos;
  2394.      switch(ToolSet){
  2395.     case 1:         // drawing tools #1
  2396.        switch(NewBoxPos){
  2397.           case 1:
  2398.          DrawTool = PENCIL;
  2399.                  DrawLineSet();
  2400.          break;
  2401.           case 2:
  2402.          DrawTool = BUCKET;
  2403.                  DrawNoSet();
  2404.          break;
  2405.           case 3:
  2406.          DrawTool = SPRAYCAN;
  2407.                  DrawLineSet();
  2408.          break;
  2409.           case 4:
  2410.          DrawTool = LINE;
  2411.          DrawLineSet();
  2412.          break;
  2413.           case 5:
  2414.          DrawTool = RECTANGLE;
  2415.                  DrawLineSet();
  2416.          break;
  2417.           case 6:
  2418.          DrawTool = CIRCLE;
  2419.          DrawLineSet();
  2420.                  break;
  2421.           case 7:
  2422.          DrawTool = FILLEDRECTANGLE;
  2423.          DrawNoSet();
  2424.                  break;
  2425.           case 8:
  2426.          DrawTool = FILLEDCIRCLE;
  2427.          DrawNoSet();
  2428.          break;
  2429.        } // switch NewBoxPos
  2430.        break;
  2431.     case 3:         // drawing tools #3
  2432.        switch(NewBoxPos){
  2433.           case 1:
  2434.          DrawTool = ZIGZAG;
  2435.                  DrawLineSet();
  2436.          break;
  2437.           case 2:
  2438.          DrawTool = COLORDOT;
  2439.                  DrawNoSet();
  2440.          break;
  2441.           case 3:
  2442.          DrawTool = CHALK;
  2443.                  DrawNoSet();
  2444.          break;
  2445.           case 4:
  2446.          DrawTool = LINEA;
  2447.                  DrawLineSet();
  2448.          break;
  2449.           case 5:
  2450.          DrawTool = LINEB;
  2451.                  DrawLineSet();
  2452.          break;
  2453.           case 6:
  2454.          DrawTool = LINEC;
  2455.          DrawLineSet();
  2456.                  break;
  2457.           case 7:
  2458.          DrawTool = LINED;
  2459.          DrawLineSet();
  2460.                  break;
  2461.           case 8:
  2462.          DrawTool = PROPELLER;
  2463.          DrawNoSet();
  2464.          break;
  2465.        }
  2466.            break;
  2467.     case 2:         // drawing tools #2
  2468.        switch(NewBoxPos){
  2469.           case 1:
  2470.          DrawTool = TRIANGLE;
  2471.          DrawLineSet();
  2472.          break;
  2473.           case 2:
  2474.          DrawTool = FILLEDTRIANGLE;
  2475.                  DrawNoSet();
  2476.          break;
  2477.           case 3:
  2478.          DrawTool = QUILLPEN;
  2479.                  DrawNoSet();
  2480.          break;
  2481.           case 4:
  2482.          DrawTool = CHARCOALPENCIL;
  2483.                  DrawNoSet();
  2484.          break;
  2485.           case 5:
  2486.          DrawTool = GOOFYLINE;
  2487.                  DrawLineSet();
  2488.          break;
  2489.           case 6:
  2490.          DrawTool = MULTIPOLY;
  2491.          DrawNoSet();
  2492.                  break;
  2493.           case 7:
  2494.          DrawTool = SMALLERASER;
  2495.          DrawNoSet();
  2496.                  break;
  2497.           case 8:
  2498.          DrawTool = LARGEERASER;
  2499.          DrawNoSet();
  2500.          break;
  2501.        } // switch NewBoxPos
  2502.            break;
  2503.         case 5:         // FX tools
  2504.        switch(NewBoxPos){
  2505.           case 1:
  2506.          DrawTool = SCISSORS;
  2507.          DrawNoSet();
  2508.          break;
  2509.           case 2:
  2510.          DrawTool = KNIFE;
  2511.                  DrawNoSet();
  2512.          break;
  2513.           case 3:
  2514.          DrawTool = FLIPH;
  2515.                  DrawNoSet();
  2516.          break;
  2517.           case 4:
  2518.          DrawTool = FLIPV;
  2519.                  DrawNoSet();
  2520.          break;
  2521.           case 5:
  2522.          DrawTool = NONE;
  2523.          DrawNoSet();
  2524.          InvertPic();
  2525.          DrawTools1();
  2526.          break;
  2527.           case 6:
  2528.          DrawTool = NONE;
  2529.          DrawNoSet();
  2530.          StretchPic();
  2531.          DrawTools1();
  2532.                  break;
  2533.           case 7:
  2534.          DrawTool = NONE;
  2535.          DrawNoSet();
  2536.          ShrinkPic();
  2537.          DrawTools1();
  2538.                  break;
  2539.           case 8:
  2540.          DrawTool = NONE;
  2541.          DrawNoSet();
  2542.          TransmogrifyColor();
  2543.                  DrawTools1();
  2544.          break;
  2545.        } // switch NewBoxPos
  2546.        break;
  2547.     case 7:         // icon stamps #1
  2548.        switch(NewBoxPos){
  2549.           case 1:
  2550.          TheIcon = LoadIcon(hInst,"ICON_52");
  2551.          DrawNoSet();
  2552.          PlaySound(79);
  2553.          break;
  2554.           case 2:
  2555.          TheIcon = LoadIcon(hInst,"ICON_53");
  2556.          DrawNoSet();
  2557.          PlaySound(54);
  2558.          break;
  2559.           case 3:
  2560.          TheIcon = LoadIcon(hInst,"ICON_54");
  2561.          DrawNoSet();
  2562.          PlaySound(49);
  2563.          break;
  2564.           case 4:
  2565.          TheIcon = LoadIcon(hInst,"ICON_55");
  2566.          DrawNoSet();
  2567.          PlaySound(73);
  2568.          break;
  2569.           case 5:
  2570.          TheIcon = LoadIcon(hInst,"ICON_56");
  2571.          DrawNoSet();
  2572.          PlaySound(76);
  2573.          break;
  2574.           case 6:
  2575.          TheIcon = LoadIcon(hInst,"ICON_57");
  2576.          DrawNoSet();
  2577.          PlaySound(81);
  2578.                  break;
  2579.           case 7:
  2580.          TheIcon = LoadIcon(hInst,"ICON_58");
  2581.          DrawNoSet();
  2582.          PlaySound(39);
  2583.                  break;
  2584.           case 8:
  2585.          TheIcon = LoadIcon(hInst,"ICON_59");
  2586.          DrawNoSet();
  2587.          PlaySound(78);
  2588.          break;
  2589.        } // switch NewBoxPos
  2590.        break;
  2591.     case 8:         // icon stamps #2
  2592.        switch(NewBoxPos){
  2593.           case 1:
  2594.          TheIcon = LoadIcon(hInst,"ICON_60");
  2595.          DrawNoSet();
  2596.          PlaySound(19);
  2597.          break;
  2598.           case 2:
  2599.          TheIcon = LoadIcon(hInst,"ICON_61");
  2600.          DrawNoSet();
  2601.          PlaySound(70);
  2602.          break;
  2603.           case 3:
  2604.          TheIcon = LoadIcon(hInst,"ICON_62");
  2605.          DrawNoSet();
  2606.          PlaySound(26);
  2607.          break;
  2608.           case 4:
  2609.          TheIcon = LoadIcon(hInst,"ICON_63");
  2610.          DrawNoSet();
  2611.          PlaySound(72);
  2612.          break;
  2613.           case 5:
  2614.          TheIcon = LoadIcon(hInst,"ICON_64");
  2615.          DrawNoSet();
  2616.          PlaySound(79);
  2617.          break;
  2618.           case 6:
  2619.          TheIcon = LoadIcon(hInst,"ICON_65");
  2620.          DrawNoSet();
  2621.          PlaySound(88);
  2622.                  break;
  2623.           case 7:
  2624.          TheIcon = LoadIcon(hInst,"ICON_66");
  2625.          DrawNoSet();
  2626.          PlaySound(87);
  2627.                  break;
  2628.           case 8:
  2629.          TheIcon = LoadIcon(hInst,"ICON_67");
  2630.          DrawNoSet();
  2631.          PlaySound(34);
  2632.          break;
  2633.        } // switch NewBoxPos
  2634.            break;
  2635.     case 9:         // icon stamps #1
  2636.        switch(NewBoxPos){
  2637.           case 1:
  2638.          TheIcon = LoadIcon(hInst,"ICON_68");
  2639.          DrawNoSet();
  2640.          PlaySound(90);
  2641.          break;
  2642.           case 2:
  2643.          TheIcon = LoadIcon(hInst,"ICON_69");
  2644.          DrawNoSet();
  2645.          PlaySound(69);
  2646.          break;
  2647.           case 3:
  2648.          TheIcon = LoadIcon(hInst,"ICON_70");
  2649.          DrawNoSet();
  2650.          PlaySound(56);
  2651.          break;
  2652.           case 4:
  2653.          TheIcon = LoadIcon(hInst,"ICON_71");
  2654.          DrawNoSet();
  2655.          PlaySound(53);
  2656.          break;
  2657.           case 5:
  2658.          TheIcon = LoadIcon(hInst,"ICON_72");
  2659.          DrawNoSet();
  2660.          PlaySound(52);
  2661.          break;
  2662.           case 6:
  2663.          TheIcon = LoadIcon(hInst,"ICON_73");
  2664.          DrawNoSet();
  2665.          PlaySound(95);
  2666.                  break;
  2667.           case 7:
  2668.          TheIcon = LoadIcon(hInst,"ICON_74");
  2669.          DrawNoSet();
  2670.          PlaySound(50);
  2671.                  break;
  2672.           case 8:
  2673.          TheIcon = LoadIcon(hInst,"ICON_75");
  2674.          DrawNoSet();
  2675.          PlaySound(102);
  2676.          break;
  2677.        } // switch NewBoxPos
  2678.            break;
  2679.     case 10:         // icon stamps #1
  2680.        switch(NewBoxPos){
  2681.           case 1:
  2682.          TheIcon = LoadIcon(hInst,"ICON_76");
  2683.          DrawNoSet();
  2684.          PlaySound(35);
  2685.          break;
  2686.           case 2:
  2687.          TheIcon = LoadIcon(hInst,"ICON_77");
  2688.          DrawNoSet();
  2689.          PlaySound(47);
  2690.          break;
  2691.           case 3:
  2692.          TheIcon = LoadIcon(hInst,"ICON_78");
  2693.          DrawNoSet();
  2694.          PlaySound(47);
  2695.          break;
  2696.           case 4:
  2697.          TheIcon = LoadIcon(hInst,"ICON_79");
  2698.          DrawNoSet();
  2699.          PlaySound(103);
  2700.          break;
  2701.           case 5:
  2702.          TheIcon = LoadIcon(hInst,"ICON_80");
  2703.          DrawNoSet();
  2704.          PlaySound(104);
  2705.          break;
  2706.           case 6:
  2707.          TheIcon = LoadIcon(hInst,"ICON_81");
  2708.          DrawNoSet();
  2709.          PlaySound(105);
  2710.                  break;
  2711.           case 7:
  2712.          TheIcon = LoadIcon(hInst,"ICON_82");
  2713.          DrawNoSet();
  2714.          PlaySound(102);
  2715.                  break;
  2716.           case 8:
  2717.          TheIcon = LoadIcon(hInst,"ICON_83");
  2718.          DrawNoSet();
  2719.          PlaySound(89);
  2720.          break;
  2721.        } // switch NewBoxPos
  2722.        break;
  2723.     case 11:         // icon stamps #1
  2724.        switch(NewBoxPos){
  2725.           case 1:
  2726.          TheIcon = LoadIcon(hInst,"ICON_84");
  2727.          DrawNoSet();
  2728.          PlaySound(103);
  2729.          break;
  2730.           case 2:
  2731.          TheIcon = LoadIcon(hInst,"ICON_85");
  2732.          DrawNoSet();
  2733.          PlaySound(104);
  2734.          break;
  2735.           case 3:
  2736.          TheIcon = LoadIcon(hInst,"ICON_86");
  2737.          DrawNoSet();
  2738.          PlaySound(93);
  2739.          break;
  2740.           case 4:
  2741.          TheIcon = LoadIcon(hInst,"ICON_87");
  2742.          DrawNoSet();
  2743.          PlaySound(38);
  2744.          break;
  2745.           case 5:
  2746.          TheIcon = LoadIcon(hInst,"ICON_88");
  2747.          DrawNoSet();
  2748.          PlaySound(32);
  2749.          break;
  2750.           case 6:
  2751.          TheIcon = LoadIcon(hInst,"ICON_89");
  2752.          DrawNoSet();
  2753.          PlaySound(51);
  2754.                  break;
  2755.           case 7:
  2756.          TheIcon = LoadIcon(hInst,"ICON_90");
  2757.          DrawNoSet();
  2758.          PlaySound(30);
  2759.                  break;
  2760.           case 8:
  2761.          TheIcon = LoadIcon(hInst,"ICON_91");
  2762.          DrawNoSet();
  2763.          PlaySound(36);
  2764.          break;
  2765.        } // switch NewBoxPos
  2766.        break;
  2767.     case 12:         // icon stamps #1
  2768.        switch(NewBoxPos){
  2769.           case 1:
  2770.          TheIcon = LoadIcon(hInst,"ICON_92");
  2771.          DrawNoSet();
  2772.          PlaySound(67);
  2773.          break;
  2774.           case 2:
  2775.          TheIcon = LoadIcon(hInst,"ICON_93");
  2776.          DrawNoSet();
  2777.          PlaySound(29);
  2778.          break;
  2779.           case 3:
  2780.          TheIcon = LoadIcon(hInst,"ICON_94");
  2781.          DrawNoSet();
  2782.          PlaySound(18);
  2783.          break;
  2784.           case 4:
  2785.          TheIcon = LoadIcon(hInst,"ICON_95");
  2786.          DrawNoSet();
  2787.          PlaySound(85);
  2788.          break;
  2789.           case 5:
  2790.          TheIcon = LoadIcon(hInst,"ICON_96");
  2791.          DrawNoSet();
  2792.          PlaySound(61);
  2793.          break;
  2794.           case 6:
  2795.          TheIcon = LoadIcon(hInst,"ICON_97");
  2796.          DrawNoSet();
  2797.          PlaySound(82);
  2798.                  break;
  2799.           case 7:
  2800.          TheIcon = LoadIcon(hInst,"ICON_98");
  2801.          DrawNoSet();
  2802.          PlaySound(63);
  2803.                  break;
  2804.           case 8:
  2805.          TheIcon = LoadIcon(hInst,"ICON_99");
  2806.          DrawNoSet();
  2807.          PlaySound(68);
  2808.          break;
  2809.        } // switch NewBoxPos
  2810.        break;
  2811.     case 13:         // icon stamps #1
  2812.        switch(NewBoxPos){
  2813.           case 1:
  2814.          TheIcon = LoadIcon(hInst,"ICON_100");
  2815.          DrawNoSet();
  2816.          PlaySound(31);
  2817.          break;
  2818.           case 2:
  2819.          TheIcon = LoadIcon(hInst,"ICON_101");
  2820.          DrawNoSet();
  2821.          PlaySound(45);
  2822.          break;
  2823.           case 3:
  2824.          TheIcon = LoadIcon(hInst,"ICON_102");
  2825.          DrawNoSet();
  2826.          PlaySound(33);
  2827.          break;
  2828.           case 4:
  2829.          TheIcon = LoadIcon(hInst,"ICON_103");
  2830.          DrawNoSet();
  2831.          PlaySound(100);
  2832.          break;
  2833.           case 5:
  2834.          TheIcon = LoadIcon(hInst,"ICON_104");
  2835.          DrawNoSet();
  2836.          PlaySound(64);
  2837.          break;
  2838.           case 6:
  2839.          TheIcon = LoadIcon(hInst,"ICON_105");
  2840.          DrawNoSet();
  2841.                  PlaySound(98);
  2842.                  break;
  2843.           case 7:
  2844.          TheIcon = LoadIcon(hInst,"ICON_106");
  2845.          DrawNoSet();
  2846.          PlaySound(60);
  2847.                  break;
  2848.           case 8:
  2849.          TheIcon = LoadIcon(hInst,"ICON_107");
  2850.          DrawNoSet();
  2851.          PlaySound(84);
  2852.          break;
  2853.        } // switch NewBoxPos
  2854.        break;
  2855.     case 14:         // icon stamps #1
  2856.        switch(NewBoxPos){
  2857.           case 1:
  2858.          TheIcon = LoadIcon(hInst,"ICON_108");
  2859.          DrawNoSet();
  2860.          PlaySound(86);
  2861.          break;
  2862.           case 2:
  2863.          TheIcon = LoadIcon(hInst,"ICON_109");
  2864.          DrawNoSet();
  2865.          PlaySound(37);
  2866.          break;
  2867.           case 3:
  2868.          TheIcon = LoadIcon(hInst,"ICON_110");
  2869.          DrawNoSet();
  2870.          PlaySound(65);
  2871.          break;
  2872.           case 4:
  2873.          TheIcon = LoadIcon(hInst,"ICON_111");
  2874.          DrawNoSet();
  2875.          PlaySound(58);
  2876.          break;
  2877.           case 5:
  2878.          TheIcon = LoadIcon(hInst,"ICON_112");
  2879.          DrawNoSet();
  2880.          PlaySound(97);
  2881.          break;
  2882.           case 6:
  2883.          TheIcon = LoadIcon(hInst,"ICON_113");
  2884.          DrawNoSet();
  2885.          PlaySound(99);
  2886.                  break;
  2887.           case 7:
  2888.          TheIcon = LoadIcon(hInst,"ICON_114");
  2889.          DrawNoSet();
  2890.          PlaySound(44);
  2891.                  break;
  2892.           case 8:
  2893.          TheIcon = LoadIcon(hInst,"ICON_115");
  2894.          DrawNoSet();
  2895.          PlaySound(77);
  2896.          break;
  2897.        } // switch NewBoxPos
  2898.        break;
  2899.        case 15:         // icon stamps #1
  2900.        switch(NewBoxPos){
  2901.           case 1:
  2902.          TheIcon = LoadIcon(hInst,"ICON_116");
  2903.          DrawNoSet();
  2904.          PlaySound(48);
  2905.          break;
  2906.           case 2:
  2907.          TheIcon = LoadIcon(hInst,"ICON_117");
  2908.          DrawNoSet();
  2909.          PlaySound(25);
  2910.          break;
  2911.           case 3:
  2912.          TheIcon = LoadIcon(hInst,"ICON_118");
  2913.          DrawNoSet();
  2914.          PlaySound(89);
  2915.          break;
  2916.           case 4:
  2917.          TheIcon = LoadIcon(hInst,"ICON_119");
  2918.          DrawNoSet();
  2919.          PlaySound(96);
  2920.          break;
  2921.           case 5:
  2922.          TheIcon = LoadIcon(hInst,"ICON_120");
  2923.          DrawNoSet();
  2924.          PlaySound(71);
  2925.          break;
  2926.           case 6:
  2927.          TheIcon = LoadIcon(hInst,"ICON_121");
  2928.          DrawNoSet();
  2929.          PlaySound(55);
  2930.                  break;
  2931.           case 7:
  2932.          TheIcon = LoadIcon(hInst,"ICON_122");
  2933.          DrawNoSet();
  2934.          PlaySound(24);
  2935.                  break;
  2936.           case 8:
  2937.          TheIcon = LoadIcon(hInst,"ICON_123");
  2938.          DrawNoSet();
  2939.          PlaySound(17);
  2940.          break;
  2941.        } // switch NewBoxPos
  2942.     break;
  2943.      } // switch ToolSet
  2944. }
  2945.  
  2946.  
  2947. void ColorTool(int which)
  2948. {
  2949.      HDC               hDC;
  2950.      HICON             hicon1, hicon2, hicon3;
  2951.      HBRUSH            hBrush, hobr;
  2952.      HPEN              hPen, hPen1, hop;
  2953.      HPALETTE          oldpal;
  2954.  
  2955.  
  2956.      hDC = GetDC(hWndMain);
  2957.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  2958.      RealizePalette(hDC);
  2959.       // blank out whatever toolextra is there
  2960.      hPen1 = CreatePen(PS_SOLID,1,TURQUOISE1 | 0x2000000L);
  2961.      hop = SelectObject(hDC,hPen1);
  2962.      hBrush = CreateSolidBrush(TURQUOISE1 | 0x2000000L);
  2963.      hobr = SelectObject(hDC,hBrush);
  2964.      Rectangle(hDC,3,339,48,430);
  2965.      // draw the tool icons
  2966.      hicon1 = LoadIcon(hInst,"ICON_3");
  2967.      hicon2 = LoadIcon(hInst,"ICON_17");
  2968.      hicon3 = LoadIcon(hInst,"ICON_50");
  2969.      DrawIcon(hDC,9,343,hicon1);
  2970.      DrawIcon(hDC,9,383,hicon2);
  2971.      DrawIcon(hDC,540,10,hicon3);
  2972.      // now draw a line around the chosen tool
  2973.      SelectObject(hDC,hop);
  2974.      hPen = CreatePen(PS_SOLID,2,RED | 0x2000000L);
  2975.      hop = SelectObject(hDC,hPen);
  2976.      if(which == 0)
  2977.     Box(hDC,5,341,45,380);
  2978.      else
  2979.     Box(hDC,5,380,45,420);
  2980.      // and clean up
  2981.      SelectObject(hDC,hop);
  2982.      SelectObject(hDC,hobr);
  2983.      SelectPalette(hDC, oldpal, FALSE);
  2984.      ReleaseDC(hWndMain,hDC);
  2985.      DeleteObject(hBrush);
  2986.      DeleteObject(hPen);
  2987.      DeleteObject(hPen1);
  2988.      DestroyIcon(hicon1);
  2989.      DestroyIcon(hicon2);
  2990.      DestroyIcon(hicon3);
  2991.      // remember to show which tool
  2992.      if(which == 0) 
  2993.     DrawTool = COLORBOOK1;
  2994.      else
  2995.         DrawTool = COLORBOOK2;
  2996. }
  2997.  
  2998.  
  2999. void ExecuteDisk(int which)
  3000. {
  3001.      HDC          hdc;
  3002.      HPALETTE     oldpal;
  3003.  
  3004.        switch(which){
  3005.           case 1:
  3006.          DrawTool = NONE;
  3007.                  trashit = FALSE;
  3008.          DrawNoSet();
  3009.          DiskToPicSelected();
  3010.          break;
  3011.           case 2:
  3012.          DrawTool = NONE;
  3013.          DrawNoSet();
  3014.          PicToDiskSelected();
  3015.          DrawTools1();
  3016.          ShowWindow(hwnd8,SW_SHOWNA);
  3017.          hdc = GetDC(phwnd);
  3018.          oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3019.                  RealizePalette(hdc);
  3020.          BitBlt(hdc,0,0,hres-50,vres-50,undodc,0,0,SRCCOPY);
  3021.          SelectPalette(hdc, oldpal, FALSE);
  3022.          ReleaseDC(phwnd,hdc);
  3023.          break;
  3024.           case 3:
  3025.              DrawTool = NONE;
  3026.              DrawNoSet();
  3027.          PrintIt();
  3028.          DrawTools1();
  3029.          ShowWindow(hwnd8,SW_SHOWNA);
  3030.          break;
  3031.           case 4:
  3032.          PlaySound(92);
  3033.          DrawTool = NONE;
  3034.                  trashit = TRUE;
  3035.          DrawNoSet();
  3036.          DiskToPicSelected();
  3037.          break;
  3038.           case 5:
  3039.          if(stampsmear == TRUE)
  3040.             stampsmear = FALSE;
  3041.          else
  3042.             stampsmear = TRUE;
  3043.          DrawTools1();
  3044.          ShowWindow(hwnd8,SW_SHOWNA);
  3045.                  break;
  3046.           case 6:
  3047.           case 7:
  3048.           case 8:
  3049.          DrawTools6();
  3050.          ShowWindow(hwnd8,SW_SHOWNA);
  3051.                  break;
  3052.        }   
  3053. }
  3054.  
  3055. void ExecuteErase(int which)
  3056. {
  3057.      HDC      hdc;
  3058.      HBRUSH   hBrush, hobr;
  3059.      HPEN     hPen, hop;
  3060.      LOGBRUSH logbrush;
  3061.      HPALETTE oldpal;
  3062.  
  3063.      int      h, i, j, k;
  3064.  
  3065.      hdc = GetDC(phwnd);
  3066.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3067.      RealizePalette(hdc);
  3068.      switch(which){
  3069.      case 1:    // Blackboard
  3070.               PlaySound(40);
  3071.           hBrush = CreateSolidBrush(DKGREEN | 0x2000000L);
  3072.           hobr = SelectObject(hdc,hBrush);
  3073.           hPen = CreatePen(PS_SOLID,1,DKGREEN | 0x2000000L);
  3074.           hop = SelectObject(hdc,hPen);
  3075.           Rectangle(hdc,0,0,hres - 50,vres - 50);
  3076.           break;
  3077.      case 2:   // Wipe Right
  3078.               PlaySound(8);
  3079.           hBrush = CreateSolidBrush(WHITE);
  3080.           hobr = SelectObject(hdc,hBrush);
  3081.           hPen = CreatePen(PS_SOLID,1,WHITE);
  3082.           hop = SelectObject(hdc,hPen);
  3083.           for(i = 0; i < hres - 50; i++) Line(hdc,i,0,i,vres - 50);
  3084.           break;
  3085.      case 3:   // Claws
  3086.               PlaySound(13);
  3087.           hBrush = CreateSolidBrush(WHITE);
  3088.           hobr = SelectObject(hdc,hBrush);
  3089.           hPen = CreatePen(PS_SOLID,7,WHITE);
  3090.           hop = SelectObject(hdc,hPen);
  3091.           for(i = 0; i < 200; i++){
  3092.           j = random(hres - 50);
  3093.           k = random(hres - 50);
  3094.           Line(hdc,j,0,k,vres - 50);
  3095.           }
  3096.           BitBlt(hdc, 0,0,hres - 50,vres - 50,NULL,0,0,WHITENESS);
  3097.           break;
  3098.      case 4:  // Curtains A
  3099.               PlaySound(9);
  3100.           hBrush = CreateSolidBrush(WHITE);
  3101.           hobr = SelectObject(hdc,hBrush);
  3102.           hPen = CreatePen(PS_SOLID,1,WHITE);
  3103.           hop = SelectObject(hdc,hPen);
  3104.               h = (hres - 52) / 2;
  3105.           for(i = h, j = h; i >= 0; i--, j++){
  3106.           Line(hdc,i,0,i,vres - 50);
  3107.           Line(hdc,j,0,j,vres - 50);
  3108.           }
  3109.           break;
  3110.      case 5:  // Curtains B
  3111.               PlaySound(10);
  3112.           hBrush = CreateSolidBrush(BLACK);
  3113.           hobr = SelectObject(hdc,hBrush);
  3114.           hPen = CreatePen(PS_SOLID,1,BLACK);
  3115.           hop = SelectObject(hdc,hPen);
  3116.           for(i = 0, j = hres - 50; i < ((hres - 50) / 2) + 2; i++, j--){
  3117.           Line(hdc,i,0,i,vres - 50);
  3118.           Line(hdc,j,0,j,vres - 50);
  3119.           }
  3120.           break;
  3121.      case 6:  // Toilet
  3122.           SaveToUndoPic();
  3123.               PlaySound(15);
  3124.           hBrush = CreateSolidBrush(WHITE);
  3125.           hobr = SelectObject(hdc,hBrush);
  3126.           hPen = CreatePen(PS_SOLID,1,WHITE);
  3127.           hop = SelectObject(hdc,hPen);
  3128.           for(i = 0; i < (vres - 50); i += 20){
  3129.               Rectangle(hdc,0,0,hres - 50,i + 1);
  3130.           BitBlt(hdc, 0,i,hres - 50,vres - 50,undodc,0,0,SRCCOPY);
  3131.           }
  3132.           BitBlt(hdc, 0,0,hres - 50,vres - 50,NULL,0,0,WHITENESS);
  3133.               break;
  3134.      case 7:  // Bombe'
  3135.               PlaySound(6);
  3136.           logbrush.lbStyle = BS_HOLLOW;
  3137.           hBrush = CreateBrushIndirect(&logbrush);
  3138.           hobr = SelectObject(hdc,hBrush);
  3139.           hPen = CreatePen(PS_SOLID,1,BLACK);
  3140.           hop = SelectObject(hdc,hPen);
  3141.           h = (hres - 50) / 2;
  3142.           j = (vres - 50) / 2;
  3143.           for(i = 1; i < 400; i+=3)
  3144.           Ellipse(hdc, h- i, j -i, h + i, j + i);
  3145.           BitBlt(hdc, 0,0,hres - 50,vres - 50,NULL,0,0,WHITENESS);
  3146.           break;
  3147.      case 8:  // Starry Nite
  3148.               PlaySound(11);
  3149.           hBrush = CreateSolidBrush(BLACK);
  3150.           hobr = SelectObject(hdc,hBrush);
  3151.           hPen = CreatePen(PS_SOLID,1,BLACK);
  3152.           hop = SelectObject(hdc,hPen);
  3153.           Rectangle(hdc,0,0,hres - 50,vres - 50);
  3154.               for(i = 0; i < 1500; i++){
  3155.           h = random(hres - 50);
  3156.           k = random(vres - 50);
  3157.           j = random(15);
  3158.           SetPixel(hdc,h,k,aColor[j] | 0x2000000L);
  3159.               }
  3160.           break;
  3161.      } // switch
  3162.      SelectObject(hdc,hobr);
  3163.      SelectObject(hdc,hop);
  3164.      SelectPalette(hdc, oldpal, FALSE);
  3165.      ReleaseDC(phwnd,hdc);
  3166.      DeleteObject(hBrush);
  3167.      DeleteObject(hPen);
  3168.      DrawTools1();
  3169. }
  3170.  
  3171. void InvertPic(void)
  3172. {
  3173.      HDC             hdc;
  3174.      HPALETTE        oldpal;
  3175.  
  3176.      hdc = GetDC(phwnd);
  3177.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3178.      RealizePalette(hdc);
  3179.      BitBlt(hdc,0,0,hres - 50,vres - 50,NULL,0,0,DSTINVERT);
  3180.      SelectPalette(hdc, oldpal, FALSE);
  3181.      ReleaseDC(phwnd,hdc);
  3182. }
  3183.  
  3184. void StretchPic(void)
  3185. {
  3186.      HDC          hdc;
  3187.      int          x,y,i,j,k,m;
  3188.      HPALETTE     oldpal;
  3189.  
  3190.      PlaySound(62);
  3191.      x = hres - 53;
  3192.      y = vres - 53;
  3193.      i = x / 10;
  3194.      j = y / 10;
  3195.      k = x - (i * 2);
  3196.      m = y - (j * 2);
  3197.      hdc = GetDC(phwnd);
  3198.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3199.      RealizePalette(hdc);
  3200.      StretchBlt(hdc,0,0,x,y,hdc,i,j,k,m,SRCCOPY);
  3201.      SelectPalette(hdc, oldpal, FALSE);
  3202.      ReleaseDC(phwnd,hdc);
  3203. }
  3204.  
  3205. void ShrinkPic(void)
  3206. {
  3207.      HDC          hdc;
  3208.      int          x,y,i,j,k,m;
  3209.      HPALETTE     oldpal;
  3210.  
  3211.  
  3212.      x = hres - 53;
  3213.      y = vres - 53;
  3214.      i = x / 10;
  3215.      j = y / 10;
  3216.      k = x - (i * 2);
  3217.      m = y - (j * 2);
  3218.      hdc = GetDC(phwnd);
  3219.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3220.      RealizePalette(hdc);
  3221.      StretchBlt(hdc,i,j,k,m,hdc,0,0,x, y,SRCCOPY);
  3222.      SelectPalette(hdc, oldpal, FALSE);
  3223.      ReleaseDC(phwnd,hdc);
  3224. }
  3225.  
  3226. void SaveToUndoPic(void)
  3227. {
  3228.      HDC          hdc;
  3229.      HPALETTE     oldpal, op1;
  3230.  
  3231.      hdc = GetDC(phwnd);
  3232.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3233.      RealizePalette(hdc);
  3234.      op1 = SelectPalette(undodc, hwndpal, FALSE);
  3235.      RealizePalette(undodc);
  3236.      BitBlt(undodc,0,0,hres-50,vres-50,hdc,0,0,SRCCOPY);
  3237.      SelectPalette(hdc, oldpal, FALSE);
  3238.      SelectPalette(hdc, op1, FALSE);
  3239.      ReleaseDC(phwnd,hdc);
  3240. }
  3241.  
  3242. void TransmogrifyColor(void)
  3243. {
  3244.      HDC         hdc;
  3245.      HBRUSH      hBrush[16], hobr;
  3246.      int         i, x, y;
  3247.      HPALETTE    oldpal;
  3248.  
  3249.      hdc = GetDC(phwnd);
  3250.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  3251.      RealizePalette(hdc);
  3252.      for(i = 0; i < 16; i++)
  3253.      hBrush[i] = CreateSolidBrush(aColor[i] | 0x2000000L);
  3254.  
  3255.      for(i = 0; i < 3; i++){
  3256.      x = random(hres - 50);
  3257.      y = random(vres - 50);
  3258.      hobr = SelectObject(hdc,hBrush[i]);
  3259.      ExtFloodFill(hdc,x,y,GetPixel(hdc,x,y) | 0x2000000L,FLOODFILLSURFACE);
  3260.      SelectObject(hdc,hobr);
  3261.      }
  3262.      SelectPalette(hdc, oldpal, FALSE);
  3263.      ReleaseDC(phwnd,hdc);
  3264.      for(i = 0; i < 16; i++)
  3265.          DeleteObject(hBrush[i]);
  3266. }
  3267. /*************************************************************************
  3268.        Draw 8 tools and the Arrow...
  3269. ***************************************************************************/
  3270.  
  3271. void NextToolSet(void)
  3272. {
  3273.     switch(ToolSet){
  3274.        case 1:
  3275.       DrawTools2();
  3276.       break;
  3277.        case 2:
  3278.       DrawTools3();
  3279.       break;
  3280.        case 3:
  3281.       DrawTools1();
  3282.       break;
  3283.        case 7:
  3284.       DrawIcons(8);
  3285.           break;
  3286.        case 8:
  3287.       DrawIcons(9);
  3288.           break;
  3289.        case 9:
  3290.       DrawIcons(10);
  3291.           break;
  3292.        case 10:
  3293.       DrawIcons(11);
  3294.           break;
  3295.        case 11:
  3296.       DrawIcons(12);
  3297.           break;
  3298.        case 12:
  3299.       DrawIcons(13);
  3300.           break;
  3301.        case 13:
  3302.       DrawIcons(14);
  3303.           break;
  3304.        case 14:
  3305.       DrawIcons(15);
  3306.           break;
  3307.        case 15:
  3308.       DrawIcons(7);
  3309.       break;
  3310.     }
  3311. }
  3312.  
  3313. void PreviousToolSet(void)
  3314. {
  3315.     switch(ToolSet){
  3316.        case 1:
  3317.       DrawTools3();
  3318.       break;
  3319.        case 2:
  3320.       DrawTools1();
  3321.       break;
  3322.        case 3:
  3323.       DrawTools2();
  3324.       break;
  3325.        case 7:
  3326.       DrawIcons(15);
  3327.           break;
  3328.        case 8:
  3329.       DrawIcons(7);
  3330.           break;
  3331.        case 9:
  3332.       DrawIcons(8);
  3333.           break;
  3334.        case 10:
  3335.       DrawIcons(9);
  3336.           break;
  3337.        case 11:
  3338.       DrawIcons(10);
  3339.           break;
  3340.        case 12:
  3341.       DrawIcons(11);
  3342.           break;
  3343.        case 13:
  3344.       DrawIcons(12);
  3345.           break;
  3346.        case 14:
  3347.       DrawIcons(13);
  3348.           break;
  3349.        case 15:
  3350.       DrawIcons(14);
  3351.       break;
  3352.     }
  3353. }
  3354.  
  3355. void DrawTools1(void)
  3356. {
  3357.      HDC               hDC;
  3358.      HICON             hicon1, hicon2, hicon3,
  3359.                hicon4, hicon5, hicon6,
  3360.                hicon7, hicon8, hicon9;
  3361.      HPALETTE          oldpal;
  3362.  
  3363.      HorizDitherPattern();
  3364.      hDC = GetDC(hWndMain);
  3365.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3366.      RealizePalette(hDC);
  3367.      hicon1 = LoadIcon(hInst,"ICON_1");
  3368.      hicon2 = LoadIcon(hInst,"ICON_3");
  3369.      hicon3 = LoadIcon(hInst,"ICON_5");
  3370.      hicon4 = LoadIcon(hInst,"ICON_6");
  3371.      hicon5 = LoadIcon(hInst,"ICON_7");
  3372.      hicon6 = LoadIcon(hInst,"ICON_8");
  3373.      hicon7 = LoadIcon(hInst,"ICON_2");
  3374.      hicon8 = LoadIcon(hInst,"ICON_9");
  3375.      hicon9 = LoadIcon(hInst,"ICON_4");
  3376.      DrawIcon(hDC,60,10,hicon1);
  3377.      DrawIcon(hDC,100,10,hicon2);
  3378.      DrawIcon(hDC,140,10,hicon3);
  3379.      DrawIcon(hDC,180,10,hicon4);
  3380.      DrawIcon(hDC,220,10,hicon5);
  3381.      DrawIcon(hDC,260,10,hicon6);
  3382.      DrawIcon(hDC,300,10,hicon7);
  3383.      DrawIcon(hDC,340,10,hicon8);
  3384.      DrawIcon(hDC,380,10,hicon9);
  3385.      SelectPalette(hDC, oldpal, FALSE);
  3386.      ReleaseDC(hWndMain,hDC);
  3387.      DestroyIcon(hicon1);
  3388.      DestroyIcon(hicon2);
  3389.      DestroyIcon(hicon3);
  3390.      DestroyIcon(hicon4);
  3391.      DestroyIcon(hicon5);
  3392.      DestroyIcon(hicon6);
  3393.      DestroyIcon(hicon7);
  3394.      DestroyIcon(hicon8);
  3395.      DestroyIcon(hicon9);
  3396.      // remember to show which tool
  3397.      ToolSet = 1;
  3398.      DrawTool = PENCIL;
  3399.      CurrentBoxPos = 2;
  3400.      BoxAroundTool(1);
  3401.      DrawLineSet();
  3402. }
  3403.  
  3404. void DrawTools2(void)
  3405. {
  3406.      HDC               hDC;
  3407.      HICON             hicon1, hicon2, hicon3,
  3408.                hicon4, hicon5, hicon6,
  3409.                hicon7, hicon8, hicon9;
  3410.      HPALETTE          oldpal;
  3411.  
  3412.      HorizDitherPattern();
  3413.      hDC = GetDC(hWndMain);
  3414.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3415.      RealizePalette(hDC);
  3416.      hicon1 = LoadIcon(hInst,"ICON_10");
  3417.      hicon2 = LoadIcon(hInst,"ICON_11");
  3418.      hicon3 = LoadIcon(hInst,"ICON_12");
  3419.      hicon4 = LoadIcon(hInst,"ICON_13");
  3420.      hicon5 = LoadIcon(hInst,"ICON_14");
  3421.      hicon6 = LoadIcon(hInst,"ICON_15");
  3422.      hicon7 = LoadIcon(hInst,"ICON_16");
  3423.      hicon8 = LoadIcon(hInst,"ICON_17");
  3424.      hicon9 = LoadIcon(hInst,"ICON_4");
  3425.      DrawIcon(hDC,60,10,hicon1);
  3426.      DrawIcon(hDC,100,10,hicon2);
  3427.      DrawIcon(hDC,140,10,hicon3);
  3428.      DrawIcon(hDC,180,10,hicon4);
  3429.      DrawIcon(hDC,220,10,hicon5);
  3430.      DrawIcon(hDC,260,10,hicon6);
  3431.      DrawIcon(hDC,300,10,hicon7);
  3432.      DrawIcon(hDC,340,10,hicon8);
  3433.      DrawIcon(hDC,380,10,hicon9);
  3434.      SelectPalette(hDC, oldpal, FALSE);
  3435.      ReleaseDC(hWndMain,hDC);
  3436.      DestroyIcon(hicon1);
  3437.      DestroyIcon(hicon2);
  3438.      DestroyIcon(hicon3);
  3439.      DestroyIcon(hicon4);
  3440.      DestroyIcon(hicon5);
  3441.      DestroyIcon(hicon6);
  3442.      DestroyIcon(hicon7);
  3443.      DestroyIcon(hicon8);
  3444.      DestroyIcon(hicon9);
  3445.      // remember to show which tool
  3446.      ToolSet = 2;
  3447.      DrawTool = TRIANGLE;
  3448.      CurrentBoxPos = 2;
  3449.      BoxAroundTool(1);
  3450.      DrawLineSet();
  3451. }
  3452.  
  3453. void DrawTools3(void)
  3454. {
  3455.      HDC               hDC;
  3456.      HICON             hicon1, hicon2, hicon3,
  3457.                hicon4, hicon5, hicon6,
  3458.                hicon7, hicon8, hicon9;
  3459.      HPALETTE          oldpal;
  3460.  
  3461.      HorizDitherPattern();
  3462.      hDC = GetDC(hWndMain);
  3463.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3464.      RealizePalette(hDC);
  3465.      hicon1 = LoadIcon(hInst,"ICON_18");
  3466.      hicon2 = LoadIcon(hInst,"ICON_19");
  3467.      hicon3 = LoadIcon(hInst,"ICON_20");
  3468.      hicon4 = LoadIcon(hInst,"ICON_21");
  3469.      hicon5 = LoadIcon(hInst,"ICON_22");
  3470.      hicon6 = LoadIcon(hInst,"ICON_24");
  3471.      hicon7 = LoadIcon(hInst,"ICON_23");
  3472.      hicon8 = LoadIcon(hInst,"ICON_25");
  3473.      hicon9 = LoadIcon(hInst,"ICON_4");
  3474.      DrawIcon(hDC,60,10,hicon1);
  3475.      DrawIcon(hDC,100,10,hicon2);
  3476.      DrawIcon(hDC,140,10,hicon3);
  3477.      DrawIcon(hDC,180,10,hicon4);
  3478.      DrawIcon(hDC,220,10,hicon5);
  3479.      DrawIcon(hDC,260,10,hicon6);
  3480.      DrawIcon(hDC,300,10,hicon7);
  3481.      DrawIcon(hDC,340,10,hicon8);
  3482.      DrawIcon(hDC,380,10,hicon9);
  3483.      SelectPalette(hDC, oldpal, FALSE);
  3484.      ReleaseDC(hWndMain,hDC);
  3485.      DestroyIcon(hicon1);
  3486.      DestroyIcon(hicon2);
  3487.      DestroyIcon(hicon3);
  3488.      DestroyIcon(hicon4);
  3489.      DestroyIcon(hicon5);
  3490.      DestroyIcon(hicon6);
  3491.      DestroyIcon(hicon7);
  3492.      DestroyIcon(hicon8);
  3493.      DestroyIcon(hicon9);
  3494.      // remember to show which tool
  3495.      ToolSet = 3;
  3496.      DrawTool = ZIGZAG;
  3497.      CurrentBoxPos = 2;
  3498.      BoxAroundTool(1);
  3499.      DrawLineSet();
  3500. }
  3501.  
  3502.  
  3503. void DrawTools4(void)
  3504. {
  3505.      HDC               hDC;
  3506.      HICON             hicon1, hicon2, hicon3,
  3507.                hicon4, hicon5, hicon6,
  3508.                hicon7, hicon8;
  3509.      HPALETTE          oldpal;
  3510.  
  3511.      HorizDitherPattern();
  3512.      hDC = GetDC(hWndMain);
  3513.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3514.      RealizePalette(hDC);
  3515.      hicon1 = LoadIcon(hInst,"ICON_26");
  3516.      hicon2 = LoadIcon(hInst,"ICON_27");
  3517.      hicon3 = LoadIcon(hInst,"ICON_28");
  3518.      hicon4 = LoadIcon(hInst,"ICON_29");
  3519.      hicon5 = LoadIcon(hInst,"ICON_30");
  3520.      hicon6 = LoadIcon(hInst,"ICON_127");
  3521.      hicon7 = LoadIcon(hInst,"ICON_32");
  3522.      hicon8 = LoadIcon(hInst,"ICON_33");
  3523.      DrawIcon(hDC,60,10,hicon1);
  3524.      DrawIcon(hDC,100,10,hicon2);
  3525.      DrawIcon(hDC,140,10,hicon3);
  3526.      DrawIcon(hDC,180,10,hicon4);
  3527.      DrawIcon(hDC,220,10,hicon5);
  3528.      DrawIcon(hDC,260,10,hicon6);
  3529.      DrawIcon(hDC,300,10,hicon7);
  3530.      DrawIcon(hDC,340,10,hicon8);
  3531.      // and clean up
  3532.      SelectPalette(hDC, oldpal, FALSE);
  3533.      ReleaseDC(hWndMain,hDC);
  3534.      DestroyIcon(hicon1);
  3535.      DestroyIcon(hicon2);
  3536.      DestroyIcon(hicon3);
  3537.      DestroyIcon(hicon4);
  3538.      DestroyIcon(hicon5);
  3539.      DestroyIcon(hicon6);
  3540.      DestroyIcon(hicon7);
  3541.      DestroyIcon(hicon8);
  3542.      // remember to show which tool
  3543.      ToolSet = 4;
  3544.      DrawTool = NONE;
  3545.      CurrentBoxPos = 1;
  3546.      DrawNoSet();     // make sure there's no line set...
  3547. }
  3548.  
  3549. void DrawTools5(void)
  3550. {
  3551.      HDC               hDC;
  3552.      HICON             hicon1, hicon2, hicon3,
  3553.                hicon4, hicon5, hicon6,
  3554.                hicon7, hicon8;
  3555.      HPALETTE          oldpal;
  3556.  
  3557.      HorizDitherPattern();
  3558.      hDC = GetDC(hWndMain);
  3559.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3560.      RealizePalette(hDC);
  3561.      hicon1 = LoadIcon(hInst,"ICON_34");
  3562.      hicon2 = LoadIcon(hInst,"ICON_35");
  3563.      hicon3 = LoadIcon(hInst,"ICON_37");
  3564.      hicon4 = LoadIcon(hInst,"ICON_38");
  3565.      hicon5 = LoadIcon(hInst,"ICON_36");
  3566.      hicon6 = LoadIcon(hInst,"ICON_39");
  3567.      hicon7 = LoadIcon(hInst,"ICON_40");
  3568.      hicon8 = LoadIcon(hInst,"ICON_41");
  3569.      DrawIcon(hDC,60,10,hicon1);
  3570.      DrawIcon(hDC,100,10,hicon2);
  3571.      DrawIcon(hDC,140,10,hicon3);
  3572.      DrawIcon(hDC,180,10,hicon4);
  3573.      DrawIcon(hDC,220,10,hicon5);
  3574.      DrawIcon(hDC,260,10,hicon6);
  3575.      DrawIcon(hDC,300,10,hicon7);
  3576.      DrawIcon(hDC,340,10,hicon8);
  3577.      SelectPalette(hDC, oldpal, FALSE);
  3578.      ReleaseDC(hWndMain,hDC);
  3579.      DestroyIcon(hicon1);
  3580.      DestroyIcon(hicon2);
  3581.      DestroyIcon(hicon3);
  3582.      DestroyIcon(hicon4);
  3583.      DestroyIcon(hicon5);
  3584.      DestroyIcon(hicon6);
  3585.      DestroyIcon(hicon7);
  3586.      DestroyIcon(hicon8);
  3587.      // remember to show which tool
  3588.      ToolSet = 5;
  3589.      DrawTool = SCISSORS;
  3590.      CurrentBoxPos = 2;
  3591.      BoxAroundTool(1);
  3592.      DrawNoSet();
  3593. }
  3594.  
  3595.  
  3596. void HorizDitherPattern(void)
  3597. {
  3598.      HDC               hDC;
  3599.      HBRUSH            hBrush1, hobr;
  3600.      HPEN              hBorderPen, hop;
  3601.      int               i, acyan;
  3602.      HPALETTE          oldpal;
  3603.  
  3604.      hDC = GetDC(hWndMain);
  3605.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3606.      RealizePalette(hDC);
  3607.      hBorderPen = CreatePen(PS_SOLID, 1,TURQUOISE1 | 0x2000000L);
  3608.      hBrush1 = CreateSolidBrush(TURQUOISE1 | 0x2000000L);
  3609.      hop = SelectObject(hDC, hBorderPen);
  3610.      hobr = SelectObject(hDC, hBrush1);
  3611.      Rectangle(hDC,50,0,540,50);
  3612.      SelectObject(hDC, hop);
  3613.      SelectObject(hDC, hobr);
  3614.      SelectPalette(hDC, oldpal, FALSE);
  3615.      ReleaseDC(hWndMain,hDC);
  3616.      DeleteObject(hBorderPen);
  3617.      DeleteObject(hBrush1);
  3618. }
  3619.  
  3620. void HorizDitherPattern2(void)
  3621. {
  3622.      HDC               hDC;
  3623.      HBRUSH            hBrush1, hobr;
  3624.      HPEN              hBorderPen, hop;
  3625.      int               i, acyan;
  3626.      HPALETTE          oldpal;
  3627.  
  3628.      hDC = GetDC(hWndMain);
  3629.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3630.      RealizePalette(hDC);
  3631.      hBorderPen = CreatePen(PS_SOLID, 1,TURQUOISE1 | 0x2000000L);
  3632.      hBrush1 = CreateSolidBrush(TURQUOISE1 | 0x2000000L);
  3633.      hop = SelectObject(hDC, hBorderPen);
  3634.      hobr = SelectObject(hDC, hBrush1);
  3635.      Rectangle(hDC,592,0,hres-66,50);
  3636.      SelectObject(hDC, hop);
  3637.      SelectObject(hDC, hobr);
  3638.      SelectPalette(hDC, oldpal, FALSE);
  3639.      ReleaseDC(hWndMain,hDC);
  3640.      DeleteObject(hBorderPen);
  3641.      DeleteObject(hBrush1);
  3642. }
  3643.  
  3644. void DrawTools6(void)       // computer ops
  3645. {
  3646.      HDC               hDC;
  3647.      HICON             hicon1, hicon2, hicon3, hicon4, hicon5;
  3648.      HPALETTE          oldpal;
  3649.  
  3650.      HorizDitherPattern();
  3651.      hDC = GetDC(hWndMain);
  3652.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3653.      RealizePalette(hDC);
  3654.      hicon1 = LoadIcon(hInst,"ICON_49");
  3655.      hicon2 = LoadIcon(hInst,"ICON_48");
  3656.      hicon3 = LoadIcon(hInst,"ICON_50");
  3657.      hicon4 = LoadIcon(hInst,"ICON_126");
  3658.      if(stampsmear == TRUE) 
  3659.     hicon5 = LoadIcon(hInst,"ICON_129");
  3660.      else
  3661.     hicon5 = LoadIcon(hInst,"ICON_130");
  3662.      DrawIcon(hDC,60,10,hicon1);
  3663.      DrawIcon(hDC,100,10,hicon2);
  3664.      DrawIcon(hDC,140,10,hicon3);
  3665.      DrawIcon(hDC,180,10,hicon4);
  3666.      DrawIcon(hDC,220,10,hicon5);
  3667.      // and clean up
  3668.      SelectPalette(hDC, oldpal, FALSE);
  3669.      ReleaseDC(hWndMain,hDC);
  3670.      DestroyIcon(hicon1);
  3671.      DestroyIcon(hicon2);
  3672.      DestroyIcon(hicon3);
  3673.      DestroyIcon(hicon4);
  3674.      DestroyIcon(hicon5);
  3675.      // remember to show which tool
  3676.      ToolSet = 6;
  3677.      DrawTool = NONE;
  3678.      CurrentBoxPos = 1;
  3679.      DrawNoSet();
  3680. }
  3681.  
  3682. void DrawIcons(int whichset)
  3683. {
  3684.      HDC               hDC;
  3685.      HICON             hicon1, hicon2, hicon3,
  3686.                hicon4, hicon5, hicon6,
  3687.                hicon7, hicon8, hicon9;
  3688.      HPALETTE          oldpal;
  3689.  
  3690.      HorizDitherPattern();
  3691.      hDC = GetDC(hWndMain);
  3692.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3693.      RealizePalette(hDC);
  3694.      hicon9 = LoadIcon(hInst,"ICON_4");
  3695.      switch(whichset){
  3696.          case 7:
  3697.               hicon1 = LoadIcon(hInst,"ICON_52");
  3698.               hicon2 = LoadIcon(hInst,"ICON_53");
  3699.               hicon3 = LoadIcon(hInst,"ICON_54");
  3700.               hicon4 = LoadIcon(hInst,"ICON_55");
  3701.               hicon5 = LoadIcon(hInst,"ICON_56");
  3702.               hicon6 = LoadIcon(hInst,"ICON_57");
  3703.               hicon7 = LoadIcon(hInst,"ICON_58");
  3704.           hicon8 = LoadIcon(hInst,"ICON_59");
  3705.               break;
  3706.           case 8:
  3707.           hicon1 = LoadIcon(hInst,"ICON_60");
  3708.               hicon2 = LoadIcon(hInst,"ICON_61");
  3709.               hicon3 = LoadIcon(hInst,"ICON_62");
  3710.               hicon4 = LoadIcon(hInst,"ICON_63");
  3711.               hicon5 = LoadIcon(hInst,"ICON_64");
  3712.               hicon6 = LoadIcon(hInst,"ICON_65");
  3713.               hicon7 = LoadIcon(hInst,"ICON_66");
  3714.           hicon8 = LoadIcon(hInst,"ICON_67");
  3715.               break;
  3716.           case 9:
  3717.               hicon1 = LoadIcon(hInst,"ICON_68");
  3718.           hicon2 = LoadIcon(hInst,"ICON_69");
  3719.               hicon3 = LoadIcon(hInst,"ICON_70");
  3720.               hicon4 = LoadIcon(hInst,"ICON_71");
  3721.               hicon5 = LoadIcon(hInst,"ICON_72");
  3722.               hicon6 = LoadIcon(hInst,"ICON_73");
  3723.               hicon7 = LoadIcon(hInst,"ICON_74");
  3724.           hicon8 = LoadIcon(hInst,"ICON_75");
  3725.               break;
  3726.           case 10:
  3727.               hicon1 = LoadIcon(hInst,"ICON_76");
  3728.               hicon2 = LoadIcon(hInst,"ICON_77");
  3729.           hicon3 = LoadIcon(hInst,"ICON_78");
  3730.               hicon4 = LoadIcon(hInst,"ICON_79");
  3731.               hicon5 = LoadIcon(hInst,"ICON_80");
  3732.               hicon6 = LoadIcon(hInst,"ICON_81");
  3733.               hicon7 = LoadIcon(hInst,"ICON_82");
  3734.           hicon8 = LoadIcon(hInst,"ICON_83");
  3735.               break;
  3736.           case 11:
  3737.               hicon1 = LoadIcon(hInst,"ICON_84");
  3738.               hicon2 = LoadIcon(hInst,"ICON_85");
  3739.               hicon3 = LoadIcon(hInst,"ICON_86");
  3740.           hicon4 = LoadIcon(hInst,"ICON_87");
  3741.               hicon5 = LoadIcon(hInst,"ICON_88");
  3742.               hicon6 = LoadIcon(hInst,"ICON_89");
  3743.               hicon7 = LoadIcon(hInst,"ICON_90");
  3744.           hicon8 = LoadIcon(hInst,"ICON_91");
  3745.               break;
  3746.           case 12:
  3747.               hicon1 = LoadIcon(hInst,"ICON_92");
  3748.               hicon2 = LoadIcon(hInst,"ICON_93");
  3749.               hicon3 = LoadIcon(hInst,"ICON_94");
  3750.               hicon4 = LoadIcon(hInst,"ICON_95");
  3751.           hicon5 = LoadIcon(hInst,"ICON_96");
  3752.               hicon6 = LoadIcon(hInst,"ICON_97");
  3753.               hicon7 = LoadIcon(hInst,"ICON_98");
  3754.           hicon8 = LoadIcon(hInst,"ICON_99");
  3755.               break;
  3756.           case 13:
  3757.               hicon1 = LoadIcon(hInst,"ICON_100");
  3758.               hicon2 = LoadIcon(hInst,"ICON_101");
  3759.               hicon3 = LoadIcon(hInst,"ICON_102");
  3760.               hicon4 = LoadIcon(hInst,"ICON_103");
  3761.               hicon5 = LoadIcon(hInst,"ICON_104");
  3762.           hicon6 = LoadIcon(hInst,"ICON_105");
  3763.               hicon7 = LoadIcon(hInst,"ICON_106");
  3764.           hicon8 = LoadIcon(hInst,"ICON_107");
  3765.               break;
  3766.           case 14: 
  3767.               hicon1 = LoadIcon(hInst,"ICON_108");
  3768.               hicon2 = LoadIcon(hInst,"ICON_109");
  3769.               hicon3 = LoadIcon(hInst,"ICON_110");
  3770.               hicon4 = LoadIcon(hInst,"ICON_111");
  3771.               hicon5 = LoadIcon(hInst,"ICON_112");
  3772.               hicon6 = LoadIcon(hInst,"ICON_113");
  3773.           hicon7 = LoadIcon(hInst,"ICON_114");
  3774.           hicon8 = LoadIcon(hInst,"ICON_115");
  3775.               break;
  3776.           case 15:
  3777.               hicon1 = LoadIcon(hInst,"ICON_116");
  3778.               hicon2 = LoadIcon(hInst,"ICON_117");
  3779.               hicon3 = LoadIcon(hInst,"ICON_118");
  3780.               hicon4 = LoadIcon(hInst,"ICON_119");
  3781.               hicon5 = LoadIcon(hInst,"ICON_120");
  3782.               hicon6 = LoadIcon(hInst,"ICON_121");
  3783.               hicon7 = LoadIcon(hInst,"ICON_122");
  3784.           hicon8 = LoadIcon(hInst,"ICON_123");
  3785.           break;
  3786.      }  // switch whichset
  3787.      DrawIcon(hDC,60,10,hicon1);
  3788.      DrawIcon(hDC,100,10,hicon2);
  3789.      DrawIcon(hDC,140,10,hicon3);
  3790.      DrawIcon(hDC,180,10,hicon4);
  3791.      DrawIcon(hDC,220,10,hicon5);
  3792.      DrawIcon(hDC,260,10,hicon6);
  3793.      DrawIcon(hDC,300,10,hicon7);
  3794.      DrawIcon(hDC,340,10,hicon8);
  3795.      DrawIcon(hDC,380,10,hicon9);
  3796.      SelectPalette(hDC, oldpal, FALSE);
  3797.      ReleaseDC(hWndMain,hDC);
  3798.      DestroyIcon(hicon1);
  3799.      DestroyIcon(hicon2);
  3800.      DestroyIcon(hicon3);
  3801.      DestroyIcon(hicon4);
  3802.      DestroyIcon(hicon5);
  3803.      DestroyIcon(hicon6);
  3804.      DestroyIcon(hicon7);
  3805.      DestroyIcon(hicon8);
  3806.      DestroyIcon(hicon9);
  3807.      // remember to show which tool
  3808.      ToolSet = whichset;
  3809.      DrawTool = ICONDRAW;
  3810.      CurrentBoxPos = 2;
  3811.      BoxAroundTool(1);
  3812. }
  3813.  
  3814.  
  3815. void ShowText(unsigned char c)
  3816. {
  3817.      HDC               hDC;
  3818.      RECT              arect;
  3819.      int               i;
  3820.      HFONT             hfont;
  3821.      HPALETTE          oldpal;
  3822.  
  3823.      SetRect(&arect,TextX,TextY,hres-50,vres-50);
  3824.      hDC = GetDC(phwnd);
  3825.      oldpal= SelectPalette(hDC, hwndpal, FALSE);
  3826.      RealizePalette(hDC);
  3827.      BitBlt(hDC,0,0,hres - 50,vres - 50,savebitmapDC,0,0,SRCCOPY);
  3828.      hfont = CreateFontIndirect(&MainFontRec);
  3829.      SelectObject(hDC, hfont);
  3830.      SetBkMode(hDC,TRANSPARENT);
  3831.      SetTextColor(hDC,CurrentColor | 0x2000000L);
  3832.      i = lstrlen(globaltextbuf);
  3833.      if(c == 0x08){      // backspace
  3834.     if(i > 0){
  3835.        globaltextbuf[i] = '\0';
  3836.        globaltextbuf[i - 1] = '\0';
  3837.        globaltextbuf[i - 2] = '|';
  3838.      }
  3839.      }
  3840.      else{
  3841.     if(i > 253){
  3842.        SelectPalette(hDC, oldpal, FALSE);
  3843.        ReleaseDC(phwnd,hDC);
  3844.            DeleteObject(hfont);
  3845.        return;
  3846.         }
  3847.     if(i > 0){
  3848.        globaltextbuf[i - 1] = c;
  3849.        globaltextbuf[i] = '|';
  3850.     }
  3851.     else{
  3852.        globaltextbuf[i] = c;
  3853.        globaltextbuf[++i] = '|';
  3854.         }
  3855.      }
  3856.      DrawText(hDC,globaltextbuf,lstrlen(globaltextbuf),&arect,DT_NOPREFIX|DT_LEFT|DT_WORDBREAK);
  3857.      SetBkMode(hDC,OPAQUE);
  3858.      SelectPalette(hDC, oldpal, FALSE);
  3859.      ReleaseDC(phwnd,hDC);
  3860.      DeleteObject(hfont);
  3861. }
  3862.  
  3863. void cleanuptext(void)
  3864. {
  3865.      HDC               hDC;
  3866.      RECT              arect;
  3867.      int               i;
  3868.      HFONT             hfont;
  3869.      HPALETTE          oldpal;
  3870.  
  3871.      SetRect(&arect,TextX,TextY,hres-50,vres-50);
  3872.      hDC = GetDC(phwnd);
  3873.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3874.      RealizePalette(hDC);
  3875.      BitBlt(hDC,0,0,hres - 50,vres - 50,savebitmapDC,0,0,SRCCOPY);
  3876.      hfont = CreateFontIndirect(&MainFontRec);
  3877.      SelectObject(hDC, hfont);
  3878.      SetBkMode(hDC,TRANSPARENT);
  3879.      SetTextColor(hDC,CurrentColor | 0x2000000L);
  3880.      i = lstrlen(globaltextbuf);
  3881.      globaltextbuf[i - 1] = '\0';
  3882.      globaltextbuf[i] = '\0';
  3883.      DrawText(hDC,globaltextbuf,lstrlen(globaltextbuf),&arect,DT_NOPREFIX|DT_LEFT|DT_WORDBREAK);
  3884.      SetBkMode(hDC,OPAQUE);
  3885.      SelectPalette(hDC, oldpal, FALSE);
  3886.      ReleaseDC(phwnd,hDC);
  3887.      DeleteObject(hfont);
  3888.      DeleteDC(savebitmapDC);
  3889.      DeleteObject(hsavebitmap);
  3890.      DoingText = FALSE;
  3891.      ReadyToDoText = FALSE;
  3892.      DrawTools1();
  3893. }
  3894.  
  3895. void DrawLineSet(void)
  3896. {
  3897.      HDC               hDC;
  3898.      HPEN              hPen2, hPen3, hop;
  3899.      int               i;
  3900.      char              buf[20];
  3901.      HPALETTE          oldpal;
  3902.  
  3903.      DrawNoSet();
  3904.      hDC = GetDC(hWndMain);
  3905.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3906.      RealizePalette(hDC);
  3907.      // create pens
  3908.      hPen2 = CreatePen(PS_SOLID,1,BLACK | 0x2000000L);
  3909.      hPen3 = CreatePen(PS_SOLID,2,RED | 0x2000000L);
  3910.      // now draw lines into place
  3911.      hop = SelectObject(hDC,hPen2);
  3912.      // single pixel wide
  3913.      Line(hDC, 430, 10, 430, 40);
  3914.      // 2 pixel wide
  3915.      Line(hDC, 449, 10, 449, 40);
  3916.      Line(hDC, 450, 10, 450, 40);
  3917.      // 3 pixel wide
  3918.      for(i = 469; i < 472; i++)
  3919.      Line(hDC, i, 10, i, 40);
  3920.      // 4 pixel wide
  3921.      for(i = 488; i < 492; i++)
  3922.      Line(hDC, i, 10, i, 40);
  3923.      // 5 pixel wide
  3924.      for(i = 507; i < 512; i++)
  3925.      Line(hDC, i, 10, i, 40);
  3926.      // 6 pixel wide
  3927.      for(i = 527; i < 533; i++)
  3928.      Line(hDC, i, 10, i, 40);
  3929.      // And now, draw the box around the current line!!!!!!!
  3930.      SelectObject(hDC,hop);
  3931.      SelectObject(hDC,hPen3);
  3932.      i = ((DrawWidth - 1) * 20) + 425;
  3933.      Box(hDC, i, 7,i + 10, 42); 
  3934.      // and clean up
  3935.      SelectObject(hDC,hop);
  3936.      SelectPalette(hDC, oldpal, FALSE);
  3937.      ReleaseDC(hWndMain,hDC);
  3938.      DeleteObject(hPen2);
  3939.      DeleteObject(hPen3);
  3940.      LineSet = TRUE;
  3941. }
  3942.  
  3943.     
  3944. void DrawNoSet(void)
  3945. {
  3946.      HDC               hDC;
  3947.      HBRUSH            hBrush1, hobr;
  3948.      HPEN              hBorderPen, hop;
  3949.      int               i, acyan;
  3950.      HPALETTE          oldpal;
  3951.  
  3952.  
  3953.      hDC = GetDC(hWndMain);
  3954.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3955.      RealizePalette(hDC);
  3956.      hBorderPen = CreatePen(PS_SOLID, 1,TURQUOISE1 | 0x2000000L);
  3957.      hBrush1 = CreateSolidBrush(TURQUOISE1 | 0x2000000L);
  3958.      hop = SelectObject(hDC, hBorderPen);
  3959.      hobr = SelectObject(hDC, hBrush1);
  3960.      Rectangle(hDC,418,0,540,50);
  3961.      SelectObject(hDC,hop);
  3962.      SelectObject(hDC,hobr);
  3963.      SelectPalette(hDC, oldpal, FALSE);
  3964.      ReleaseDC(hWndMain,hDC);
  3965.      DeleteObject(hBorderPen);
  3966.      DeleteObject(hBrush1);
  3967.      LineSet = FALSE;
  3968. }
  3969.  
  3970. void BlankIconArea(int icondraw)  // used in picture routines
  3971. {
  3972.      HDC               hDC;
  3973.      HICON             hicon;
  3974.      HPALETTE          oldpal;
  3975.  
  3976.      HorizDitherPattern();
  3977.      hDC = GetDC(hWndMain);
  3978.      oldpal = SelectPalette(hDC, hwndpal, FALSE);
  3979.      RealizePalette(hDC);
  3980.      if(icondraw){
  3981.     hicon = LoadIcon(hInst,"ICON_128");
  3982.     DrawIcon(hDC,480,10,hicon);
  3983.      }
  3984.      SelectPalette(hDC, oldpal, FALSE);
  3985.      ReleaseDC(hWndMain,hDC);
  3986.      if(icondraw) DestroyIcon(hicon);
  3987. }
  3988.  
  3989. /*
  3990.  
  3991.     File and Directory stuff
  3992.  
  3993.     These routines allow us to to work with data files (paintings) directly
  3994.     rather than rely strictly on the "normal" Win3 file system. Essentially
  3995.     what happens here is to present a series of pictures on screen that are
  3996.     mini-paintings (i.e. thumbnails) that a child can choose from. 
  3997.  
  3998.     The object of doing things this way is simply due to the target audience.
  3999.     We don't need 6 year olds trying to navigate Windows dialogs and the
  4000.     file system. It is also in keeping with the UI mapped out for this program;
  4001.     everything is consistent.
  4002.  
  4003.     We call FindOurDirectory in the WM_PAINT procedure of the main app window
  4004.     as we start the app. TheFileList() is called as needed; it fills filearray[]
  4005.     with a list of valid filenames.
  4006.      
  4007. */
  4008.  
  4009. void FindOurDirectory(void)
  4010. {
  4011.      HANDLE     us;
  4012.      char       buffer[100];
  4013.      int        bufflen, i;
  4014.      struct ffblk f;
  4015.  
  4016.      // this is a trick we play to find our directory so that
  4017.      // we can load/save files. First, we look for our name
  4018.      // and we use this to get Windows to pass us the directory
  4019.      // we started from.
  4020.      us = GetModuleHandle("paint.exe");
  4021.      bufflen = GetModuleFileName(us,buffer,100);
  4022.      // this returns the full path!
  4023.      // parse for first backslash (i.e. get rid of the filename)
  4024.      for(i = bufflen; i > 0; i--){
  4025.      if(buffer[i] == '\\') break;
  4026.      }
  4027.      memset(ourdir,'\0',100);   // NULL it out first!
  4028.      strncpy(ourdir,buffer,i);
  4029. }
  4030.         
  4031. void TheFileList(void)
  4032. {
  4033.      char   buf[15];
  4034.      int    done, i;
  4035.      struct ffblk f;
  4036.  
  4037.      chthedir(OUT);                        // put us in our own directory/folder
  4038.      for(i = 0; i < 79; i++)               // reset file array to NULLs
  4039.      memset(filearray[i],'\0',15);
  4040.      memset(buf,'\0',15);                  // make sure this is NULLs, too
  4041.      numfiles = 1;
  4042.      // the "look" routine
  4043.      done = findfirst("*.dib",&f,0);
  4044.      while(!done){                         // get all DATA files 
  4045.        sprintf(buf,"%s", f.ff_name);
  4046.            if(strlen(buf) > 1){
  4047.           strncat(filearray[numfiles],buf,strlen(buf)); 
  4048.           strupr(filearray[numfiles++]);
  4049.            }
  4050.        memset(buf,'\0',15);            // reset to NULLs
  4051.        done = findnext(&f);
  4052.            if(numfiles > 78) break;        // at least up to 80 
  4053.      }
  4054.      // numfiles is actually 1 greater than the number of files since the
  4055.      // filearray[] base we really use is 1 and not 0.
  4056. }
  4057.  
  4058. /************************************************************************
  4059.  
  4060.     This group of routines is responsible for OPENing a picture to edit.
  4061.  
  4062. *************************************************************************/     
  4063.  
  4064.  
  4065. /*
  4066.     Respond to the young user wanting to OPEN a file. At this point the
  4067.     DISK/PRINT button has been pressed and the DISK->PICTURE icon has been
  4068.     selected.
  4069. */
  4070.  
  4071.  
  4072. void DiskToPicSelected(void)
  4073. {
  4074.  
  4075.      numfiles = 1;
  4076.      firstfileshown = 1;
  4077.      lastfileshown = 1;
  4078.  
  4079.      TheFileList();              // get valid picture file list
  4080.      if(numfiles < 2){           // none available
  4081.         DrawTools1();            // reset to default drawing conditions
  4082.     return;
  4083.      }    
  4084.      firstfileshown = 1;
  4085.      if(numfiles > 5)
  4086.     lastfileshown = 5;
  4087.      else
  4088.     lastfileshown = numfiles;
  4089.      DisplayPics();
  4090.      Thumbnails = TRUE;
  4091. }
  4092.  
  4093.  
  4094.  // we have more than 5 pictures to see and the user wants to see more
  4095.  
  4096. void MorePicsSelected(void)
  4097. {
  4098.      int       first,last;
  4099.  
  4100.      first = lastfileshown + 1;
  4101.      if(first > numfiles){      // we have cycled all the way, so restart.
  4102.     firstfileshown = 1;
  4103.     lastfileshown = 5;
  4104.      }
  4105.      else{
  4106.         firstfileshown = first;   // reset the pointer
  4107.         if((firstfileshown + 4) < numfiles)
  4108.         lastfileshown = firstfileshown + 4;
  4109.         else
  4110.         lastfileshown = numfiles;
  4111.      }
  4112.      DisplayPics();
  4113. }
  4114.  
  4115. void DisplayPics(void)
  4116. {
  4117.      int         i,j, x;
  4118.      OFSTRUCT    of;
  4119.      HFILE       fh;
  4120.      HDC         hdc;
  4121.      HANDLE      dh;
  4122.      HPALETTE    oldpal;
  4123.  
  4124.      if(numfiles > 6)
  4125.     BlankIconArea(1);      // draw an arrow (MORE) icon
  4126.      else
  4127.     BlankIconArea(0);      // don't need a more icon
  4128.  
  4129.      hdc = GetDC(hWndMain);
  4130.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  4131.      RealizePalette(hdc);
  4132.      SetStretchBltMode(hdc,COLORONCOLOR);
  4133.      for(i = firstfileshown, j = 0; i <= lastfileshown; i++, j++){
  4134.      (HFILE)fh= OpenFile(filearray[i],&of,OF_READ); // open the file
  4135.          if((HFILE)fh != -1){
  4136.         (HANDLE)dh = OpenDIB((HFILE)fh);                 // read the DIB
  4137.         _lclose((HFILE)fh);
  4138.         x = (j * 80) + 60;
  4139.         StretchDibBlt(hdc,x,5,60,40,(HANDLE)dh,0,0,-1,-1,SRCCOPY,0);
  4140.         GlobalFree((HANDLE)dh);
  4141.          }
  4142.      }
  4143.      SelectPalette(hdc, oldpal, FALSE);
  4144.      ReleaseDC(hWndMain,hdc);
  4145. }
  4146.  
  4147.  
  4148. void ColorBookPics(int setnum)
  4149. {
  4150.      int         i,j, x;
  4151.      OFSTRUCT    of;
  4152.      HFILE       fh;
  4153.      HDC         hdc;
  4154.      HANDLE      dh;
  4155.      char        bmpname[20];
  4156.      HPALETTE    oldpal;
  4157.  
  4158.      hdc = GetDC(hWndMain);
  4159.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  4160.      RealizePalette(hdc);
  4161.      SetStretchBltMode(hdc,COLORONCOLOR);
  4162.      if(setnum == 1){
  4163.         for(i = 0; i <= 4; i++){
  4164.         // This section is to allow a bmp to be read in as a
  4165.         // color book module picture that is sized to the
  4166.         // thumbnail. Essentially, the idea is to have the
  4167.         // tiny little picture the same name as the BMP to read
  4168.         // EXCEPT that the thumbnail will have a slightly
  4169.         // different file extension... e.g. if the BMP to read
  4170.         // was ANIMAL1.BMP, the thumbnail would be stored as
  4171.         // ANIMAL1.BM1...
  4172.         memset(bmpname,'\0',20);           // reset the char array
  4173.         strcpy(bmpname, colorbmpname[i]);  // copy the name
  4174.         x = lstrlen(bmpname);              // find the length
  4175.         if(x > 4) bmpname[--x] = '1';      // if long enough, add a "1" to the end.
  4176.         fh= OpenFile(bmpname,&of,OF_READ); // open the file
  4177.             if(fh != -1){
  4178.            (HANDLE)dh = OpenDIB(fh);          // read the Bitmap
  4179.            _lclose(fh);
  4180.            x = (i * 80) + 60;
  4181.            StretchDibBlt(hdc,x,5,60,40,(HANDLE)dh,0,0,-1,-1,SRCCOPY,0);
  4182.            GlobalFree((HANDLE)dh);
  4183.             }
  4184.     }
  4185.      }
  4186.      else{
  4187.     for(i = 5; i <= 9; i++){
  4188.         memset(bmpname,'\0',20);           // reset the char array
  4189.         strcpy(bmpname, colorbmpname[i]);  // copy the name
  4190.         x = lstrlen(bmpname);              // find the length
  4191.         if(x > 4) bmpname[--x] = '1';      // if long enough, add a "1" to the end.
  4192.         fh= OpenFile(bmpname,&of,OF_READ); // open the file
  4193.             if(fh != -1){
  4194.            (HANDLE)dh = OpenDIB(fh);          // read the Bitmap
  4195.            _lclose(fh);
  4196.            x = ((i - 5) * 80) + 60;
  4197.            StretchDibBlt(hdc,x,5,60,40,(HANDLE)dh,0,0,-1,-1,SRCCOPY,0);
  4198.            GlobalFree((HANDLE)dh);
  4199.             }
  4200.     }
  4201.      }
  4202.      SelectPalette(hdc, oldpal, FALSE);
  4203.      ReleaseDC(hWndMain,hdc);
  4204. }
  4205.  
  4206. void ColorBookPicked(int whoIam)
  4207. {
  4208.      OFSTRUCT    of;
  4209.      HFILE       filehandle;
  4210.      HDC         hdc;
  4211.      HANDLE      dibhandle;
  4212.      HPALETTE    oldpal;
  4213.  
  4214.      hdc = GetDC(phwnd);
  4215.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  4216.      RealizePalette(hdc);
  4217.      if(colorset == 1)
  4218.     filehandle = OpenFile(colorbmpname[whoIam],&of,OF_READ); // open the file
  4219.      else
  4220.     filehandle = OpenFile(colorbmpname[whoIam + 5],&of,OF_READ); // open the file
  4221.      if(filehandle != -1){
  4222.     dibhandle = OpenDIB(filehandle);                 // read the DIB
  4223.         _lclose(filehandle);
  4224.         StretchDibBlt(hdc,0,0,hres - 50,vres - 50,dibhandle,0,0,-1,-1,SRCCOPY,0);
  4225.     GlobalFree(dibhandle);
  4226.      }
  4227.      SelectPalette(hdc, oldpal, FALSE);
  4228.      ReleaseDC(phwnd,hdc);
  4229. }
  4230.  
  4231.  
  4232. // we now know that the user has selected a picture, and we have a number
  4233. // that ought to point to the proper picture file
  4234.  
  4235. void UserPickedMe(int whoIam)
  4236. {
  4237.      OFSTRUCT    of;
  4238.      HFILE       filehandle;
  4239.      HDC         hdc;
  4240.      HANDLE      dibhandle;
  4241.      HPALETTE    oldpal;
  4242.  
  4243.      if(whoIam > numfiles) return; 
  4244.      hdc = GetDC(phwnd);
  4245.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  4246.      RealizePalette(hdc);
  4247.      if(trashit == FALSE){
  4248.     (HFILE)filehandle = OpenFile(filearray[whoIam],&of,OF_READ); // open the file
  4249.         (HANDLE)dibhandle = OpenDIB((HFILE)filehandle);                 // read the DIB
  4250.         _lclose((HFILE)filehandle);
  4251.     StretchDibBlt(hdc,0,0,hres - 50,vres - 50,(HANDLE)dibhandle,0,0,-1,-1,SRCCOPY,0);
  4252.     GlobalFree((HANDLE)dibhandle);
  4253.      }
  4254.      else{    // trash can was selected, so kill the file
  4255.     remove(filearray[whoIam]);
  4256.     MessageBox(hWndMain,"PICTURE DELETED!"," ", MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
  4257.      }
  4258.      SelectPalette(hdc, oldpal, FALSE);
  4259.      ReleaseDC(phwnd,hdc);
  4260.      trashit = FALSE;
  4261.      Thumbnails = FALSE;
  4262.      ShowWindow(hwnd8,SW_SHOWNA);  // show undo window
  4263.      DrawTools1();
  4264. }
  4265.  
  4266. /********************* End of Picture Open Routines *****************************/
  4267.  
  4268. /*
  4269.      The user wants to save the current picture.
  4270.  
  4271. */
  4272.  
  4273. void PicToDiskSelected(void)
  4274. {
  4275.      char     afilename[200], tempbuffer[100], namebuffer[100];
  4276.      HDC      hdc, memdc;
  4277.      int      i, j, nbpointer;
  4278.      HFILE    fh;
  4279.      OFSTRUCT of;
  4280.      HANDLE   hdib;
  4281.      HBITMAP  hbitmap;
  4282.      HPALETTE oldpal, op1;
  4283.  
  4284.  
  4285.      SaveToUndoPic();          // make a copy of the picture
  4286.      chthedir(OUT);            // make sure we're looking at the right place
  4287.      if(DiskOK() == 0) return; // complain and quit if not enough room!
  4288.      hdc = GetDC(phwnd);
  4289.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  4290.      RealizePalette(hdc);
  4291.      // First, we need to create a filename to use. Since the UI
  4292.      // doesn't rely on filenames we can name it anything we like.
  4293.      // This keeps the user from having to worry about having to name things.
  4294.  
  4295.      memset(afilename,'\0',200);               // make sure buffers are clean
  4296.      memset(namebuffer,'\0',100);
  4297.      memset(tempbuffer,'\0',100);
  4298.      GetTempFileName(0,"A",0,afilename);     // create a unique name
  4299.      // name will look like d:\path\name.tmp, so....
  4300.      // parse to get first backslash 
  4301.      for(i = 200; i > 0; i--){
  4302.      if(afilename[i] == '\\') break;
  4303.      }
  4304.      // i now points to the backslash that separates the
  4305.      // filename from the path, so......
  4306.      // copy char by char into tempbuffer
  4307.      nbpointer = 0;
  4308.      for(j = (i + 1); j < (i + 16); j++){
  4309.          if(afilename[j] == '\0') break;
  4310.      tempbuffer[nbpointer++] = afilename[j];
  4311.      }
  4312.      tempbuffer[0] = 'K';
  4313.      // namebuffer now has a copy of the filename to use...
  4314.      // and we copy all but the extension.
  4315.      strncpy(namebuffer,tempbuffer,lstrlen(tempbuffer) - 4);
  4316.      // now we append our own DIB extension to it...
  4317.      // and we have the COMPLETE filename to use. Next we
  4318.      // need to get a File Handle.
  4319.      strcat(namebuffer,".DIB");
  4320.      chthedir(OUT);
  4321.      (HFILE)fh = OpenFile(namebuffer,&of,OF_CREATE);
  4322.      //
  4323.      // look for us to bomb out
  4324.      //
  4325.      // per Amory Gabel 9/94
  4326.      //
  4327.      if((HFILE)fh == -1){   // disk too full error
  4328.      MessageBox(hWndMain,"Write Error!"," ", MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  4329.      DeleteDC(memdc);
  4330.          DeleteObject(hbitmap);
  4331.      DeleteObject((HFILE)fh);
  4332.      SelectPalette(hdc, oldpal, FALSE);
  4333.      ReleaseDC(phwnd,hdc);
  4334.      return;
  4335.      }
  4336.  
  4337.      // Second, we need to capture phwnd's picture and create a DIB for
  4338.      // it which we will then write to the disk.
  4339.      memdc = CreateCompatibleDC(hdc);
  4340.      hbitmap = CreateCompatibleBitmap(hdc,hres - 53,vres - 53);
  4341.      SelectObject(memdc,hbitmap);
  4342.      op1 = SelectPalette(memdc, hwndpal, FALSE);
  4343.      RealizePalette(memdc);
  4344.      BitBlt(memdc,0,0,hres - 53,vres - 53,hdc,0,0,SRCCOPY);
  4345.  
  4346.      // hbitmap now has a copy of the screen pic.
  4347.      (HANDLE)hdib = DibFromBitmap(hbitmap,BI_RLE8,8,hwndpal,DIB_RGB_COLORS);
  4348.      SelectPalette(hdc, op1, FALSE);
  4349.      //BitBlt(hdc,0,0,hres - 53,vres - 53,memdc,0,0,SRCCOPY);
  4350.      WriteDIB((HFILE)fh,(HANDLE)hdib);
  4351.      _lclose((HFILE)fh);
  4352.      SelectPalette(hdc, op1, FALSE);
  4353.      DeleteDC(memdc);
  4354.      DeleteObject(hbitmap);
  4355.      GlobalFree((HANDLE)hdib);
  4356.      MessageBox(hWndMain,"PICTURE SAVED!"," ", MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
  4357.      SelectPalette(hdc, oldpal, FALSE);
  4358.      ReleaseDC(phwnd,hdc);
  4359. }
  4360.  
  4361.  
  4362. void PrintIt(void)
  4363. {
  4364.      HDC       hdc, prdc,memdc;
  4365.      HBITMAP   hbitmap;
  4366.      HANDLE    hdib;
  4367.      char      buf[60], cprn[64], *cdrv, *cdev, *cop;
  4368.      int       pw,ph,tst;
  4369.      HPALETTE  oldpal, op1;
  4370.  
  4371.      SaveToUndoPic();
  4372.      hdc = GetDC(phwnd);
  4373.      SelectPalette(hdc, hwndpal, FALSE);
  4374.      oldpal = RealizePalette(hdc);
  4375.      memdc = CreateCompatibleDC(hdc);
  4376.      hbitmap = CreateCompatibleBitmap(hdc,hres - 53,vres - 53);
  4377.      SelectObject(memdc,hbitmap);
  4378.      op1 = SelectPalette(memdc, hwndpal, FALSE);
  4379.      RealizePalette(memdc);
  4380.      BitBlt(memdc,0,0,hres - 53,vres - 53,hdc,0,0,SRCCOPY);
  4381.      hdib = DibFromBitmap(hbitmap,BI_RGB,8,hwndpal,DIB_RGB_COLORS);
  4382.      GetProfileString("Windows","device","",cprn,64);
  4383.      cdev = strtok(cprn,",");
  4384.      cdrv = strtok(NULL,",");
  4385.      cop =  strtok(NULL,",");
  4386.      prdc = CreateDC(cdrv,cdev,cop,NULL);
  4387.      pw = GetDeviceCaps(prdc,HORZRES);
  4388.      ph = GetDeviceCaps(prdc,VERTRES);
  4389.      if(ph > pw){
  4390.     ph /= 2;
  4391.     ph += (ph / 5);
  4392.      }
  4393.      tst = Escape(prdc,STARTDOC,7,"KAPRINT",NULL);
  4394.      if(tst){
  4395.     memset(buf,'\0',50);
  4396.     sprintf(buf," ");
  4397.     TextOut(prdc,50,50,buf,lstrlen(buf));
  4398.     StretchDibBlt(prdc,0,0,pw,ph,
  4399.               hdib, 0,0,-1,-1,SRCCOPY,DIB_RGB_COLORS);
  4400.     Escape(prdc,NEWFRAME,NULL,NULL,NULL);
  4401.     Escape(prdc,  ENDDOC,NULL,NULL,NULL);
  4402.      }
  4403.      SelectPalette(memdc, op1, FALSE);
  4404.      DeleteDC(memdc);
  4405.      DeleteObject(hbitmap);
  4406.      GlobalFree(hdib);
  4407.      DeleteDC(prdc);
  4408.      MessageBox(hWndMain,"PICTURE PRINTED!"," ", MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
  4409.      BitBlt(hdc,0,0,hres-50,vres-50,undodc,0,0,SRCCOPY);
  4410.      SelectPalette(hdc, oldpal, FALSE);
  4411.      ReleaseDC(phwnd,hdc);
  4412.  
  4413. }
  4414.  
  4415.  
  4416. void PlaySound(int which)
  4417. {
  4418.     char       buf[20];
  4419.  
  4420.     memset(buf,20,'\0');                // get the buffer ready
  4421.     chthedir(IN);                      // make sure we're in our directory
  4422.     switch(which){
  4423.        case 1:
  4424.         strcpy(buf,"vacuum.wav");      
  4425.         break;
  4426.        case 2:
  4427.         strcpy(buf,"uhoh.wav");
  4428.         break;
  4429.        case 3:
  4430.         strcpy(buf,"splat.wav");
  4431.         break;
  4432.        case 4:
  4433.         strcpy(buf,"spray.wav");
  4434.         break;
  4435.        case 5:
  4436.         strcpy(buf,"plop.wav");
  4437.         break;
  4438.        case 6:
  4439.         strcpy(buf,"bomb.wav");
  4440.         break;
  4441.        case 7:
  4442.         strcpy(buf,"typewrit.wav");
  4443.         break;
  4444.        case 8:
  4445.         strcpy(buf,"erase1.wav");
  4446.         break;
  4447.        case 9:
  4448.         strcpy(buf,"erase2.wav");
  4449.         break;
  4450.        case 10:
  4451.         strcpy(buf,"erase3.wav");
  4452.         break;
  4453.        case 11:
  4454.         strcpy(buf,"erase4.wav");
  4455.         break;
  4456.        case 12:
  4457.         strcpy(buf,"radio.wav");
  4458.         break;
  4459.        case 13:
  4460.         strcpy(buf,"tear.wav");
  4461.         break;
  4462.        case 14:
  4463.         strcpy(buf,"bucket.wav");
  4464.         break;
  4465.        case 15:
  4466.         strcpy(buf,"toilet.wav");
  4467.         break;
  4468.        case 16:
  4469.         strcpy(buf,"thud.wav");
  4470.         break;
  4471.        case 17:
  4472.         strcpy(buf,"bell.wav");
  4473.         break;
  4474.        case 18:
  4475.         strcpy(buf,"black.wav");
  4476.         break;
  4477.        case 19:
  4478.         strcpy(buf,"bottle.wav");
  4479.         break;
  4480.        case 20:
  4481.         strcpy(buf,"bowtie.wav");
  4482.         break;
  4483.        case 21:
  4484.         strcpy(buf,"box.wav");
  4485.         break;
  4486.        case 22:
  4487.         strcpy(buf,"boxfill.wav");
  4488.         break;
  4489.        case 23:
  4490.         strcpy(buf,"brown.wav");
  4491.         break;
  4492.        case 24:
  4493.         strcpy(buf,"buterfly.wav");
  4494.         break;
  4495.        case 25:
  4496.         strcpy(buf,"candican.wav");
  4497.         break;
  4498.        case 26:
  4499.         strcpy(buf,"cat.wav");
  4500.         break;
  4501.        case 27:
  4502.         strcpy(buf,"circle.wav");
  4503.         break;
  4504.        case 28:
  4505.         strcpy(buf,"circle2.wav");
  4506.         break;
  4507.        case 29:
  4508.         strcpy(buf,"clock.wav");
  4509.         break;
  4510.        case 30:
  4511.         strcpy(buf,"cloud.wav");
  4512.         break;
  4513.        case 31:
  4514.         strcpy(buf,"clover.wav");
  4515.         break;
  4516.        case 32:
  4517.         strcpy(buf,"colrsphr.wav");
  4518.         break;
  4519.        case 33:
  4520.         strcpy(buf,"column.wav");
  4521.         break;
  4522.        case 34:
  4523.         strcpy(buf,"cow.wav");
  4524.         break;
  4525.        case 35:
  4526.         strcpy(buf,"cowboots.wav");
  4527.         break;
  4528.        case 36:
  4529.         strcpy(buf,"dino.wav");
  4530.         break;
  4531.        case 37:
  4532.         strcpy(buf,"dino2.wav");
  4533.         break;
  4534.        case 38:
  4535.         strcpy(buf,"dog.wav");
  4536.         break;
  4537.        case 39:
  4538.         strcpy(buf,"duck.wav");
  4539.         break;
  4540.        case 40:
  4541.         strcpy(buf,"erascree.wav");
  4542.         break;
  4543.        case 41:
  4544.         strcpy(buf,"eraser.wav");
  4545.         break;
  4546.        case 42:
  4547.         strcpy(buf,"exit.wav");
  4548.         break;
  4549.        case 43:
  4550.         strcpy(buf,"fan.wav");
  4551.         break;
  4552.        case 44:
  4553.         strcpy(buf,"fire.wav");
  4554.         break;
  4555.        case 45:
  4556.         strcpy(buf,"flagpole.wav");
  4557.         break;
  4558.        case 46:
  4559.         strcpy(buf,"flesh.wav");
  4560.         break;
  4561.        case 47:
  4562.         strcpy(buf,"flower.wav");
  4563.         break;
  4564.        case 48:
  4565.         strcpy(buf,"goldchst.wav");
  4566.         break;
  4567.        case 49:
  4568.         strcpy(buf,"goose.wav");
  4569.         break;
  4570.        case 50:
  4571.         strcpy(buf,"grass.wav");
  4572.         break;
  4573.        case 51:
  4574.         strcpy(buf,"gray.wav");
  4575.         break;
  4576.        case 52:
  4577.         strcpy(buf,"green.wav");
  4578.         break;
  4579.        case 53:
  4580.         strcpy(buf,"green2.wav");
  4581.         break;
  4582.        case 54:
  4583.         strcpy(buf,"hay.wav");
  4584.         break;
  4585.        case 55:
  4586.         strcpy(buf,"heart.wav");
  4587.         break;
  4588.        case 56:
  4589.         strcpy(buf,"horse.wav");
  4590.         break;
  4591.        case 57:
  4592.         strcpy(buf,"hourglas.wav");
  4593.         break;
  4594.        case 58:
  4595.         strcpy(buf,"jelifish.wav");
  4596.         break;
  4597.        case 59:
  4598.         strcpy(buf,"linefill.wav");
  4599.         break;
  4600.        case 60:
  4601.         strcpy(buf,"lips.wav");
  4602.         break;
  4603.        case 61:
  4604.         strcpy(buf,"lock.wav");
  4605.         break;
  4606.        case 62:
  4607.         strcpy(buf,"magnify.wav");
  4608.         break;
  4609.        case 63:
  4610.         strcpy(buf,"mailbox.wav");
  4611.         break;
  4612.        case 64:
  4613.         strcpy(buf,"moon.wav");
  4614.         break;
  4615.        case 65:
  4616.         strcpy(buf,"octopus.wav");
  4617.         break;
  4618.        case 66:
  4619.         strcpy(buf,"paintstk.wav");
  4620.         break;
  4621.        case 67:
  4622.         strcpy(buf,"penguin.wav");
  4623.         break;
  4624.        case 68:
  4625.         strcpy(buf,"phone.wav");
  4626.         break;
  4627.        case 69:
  4628.         strcpy(buf,"pig.wav");
  4629.         break;
  4630.        case 70:
  4631.         strcpy(buf,"pink.wav");
  4632.         break;
  4633.        case 71:
  4634.         strcpy(buf,"planet.wav");
  4635.         break;
  4636.        case 72:
  4637.         strcpy(buf,"pumpkin.wav");
  4638.         break;
  4639.        case 73:
  4640.         strcpy(buf,"rabbit.wav");
  4641.         break;
  4642.        case 74:
  4643.         strcpy(buf,"recycle.wav");
  4644.         break;
  4645.        case 75:
  4646.         strcpy(buf,"recycle2.wav");
  4647.         break;
  4648.        case 76:
  4649.         strcpy(buf,"red.wav");
  4650.         break;
  4651.        case 77:
  4652.         strcpy(buf,"ring.wav");
  4653.         break;
  4654.        case 78:
  4655.         strcpy(buf,"royalblu.wav");
  4656.         break;
  4657.        case 79:
  4658.         strcpy(buf,"scarecro.wav");
  4659.         break;
  4660.        case 80:
  4661.         strcpy(buf,"scissor.wav");
  4662.         break;
  4663.        case 81:
  4664.         strcpy(buf,"shark.wav");
  4665.         break;
  4666.        case 82:
  4667.         strcpy(buf,"spacship.wav");
  4668.         break;
  4669.        case 83:
  4670.         strcpy(buf,"spray.wav");
  4671.         break;
  4672.        case 84:
  4673.         strcpy(buf,"star.wav");
  4674.         break;
  4675.        case 85:
  4676.         strcpy(buf,"sun.wav");
  4677.         break;
  4678.        case 86:
  4679.         strcpy(buf,"sunglass.wav");
  4680.         break;
  4681.        case 87:
  4682.         strcpy(buf,"teepee.wav");
  4683.         break;
  4684.        case 88:
  4685.         strcpy(buf,"tools.wav");
  4686.         break;
  4687.        case 89:
  4688.         strcpy(buf,"toywagon.wav");
  4689.         break;
  4690.        case 90:
  4691.         strcpy(buf,"tractor.wav");
  4692.         break;
  4693.        case 91:
  4694.         strcpy(buf,"transtoo.wav");
  4695.         break;
  4696.        case 92:
  4697.         strcpy(buf,"trashca2.wav");
  4698.         break;
  4699.        case 93:
  4700.         strcpy(buf,"trashcan.wav");
  4701.         break;
  4702.        case 94:
  4703.         strcpy(buf,"trifill.wav");
  4704.         break;
  4705.        case 95:
  4706.         strcpy(buf,"turkey.wav");
  4707.         break;
  4708.        case 96:
  4709.         strcpy(buf,"turtle.wav");
  4710.         break;
  4711.        case 97:
  4712.         strcpy(buf,"umbrela.wav");
  4713.         break;
  4714.        case 98:
  4715.         strcpy(buf,"wicker.wav");
  4716.         break;
  4717.        case 99:
  4718.         strcpy(buf,"yellobox.wav");
  4719.         break;
  4720.        case 100:
  4721.         strcpy(buf,"yellow.wav");
  4722.         break;
  4723.        case 101:
  4724.         strcpy(buf,"thud2.wav");
  4725.         break;
  4726.        case 102:
  4727.         strcpy(buf,"thikpen1.wav");
  4728.         break;
  4729.        case 103:
  4730.         strcpy(buf,"thikpen2.wav");
  4731.         break;
  4732.        case 104:
  4733.         strcpy(buf,"thikpen3.wav");
  4734.         break;
  4735.        case 105:
  4736.         strcpy(buf,"thikpen4.wav");
  4737.         break;
  4738.        case 106:
  4739.         strcpy(buf,"thikpen5.wav");
  4740.         break;
  4741.        case 107:
  4742.         strcpy(buf,"clink.wav");
  4743.         break;
  4744.        case 108:
  4745.         strcpy(buf,"w2.wav");
  4746.         break;
  4747.  
  4748.     }
  4749.     sndPlaySound(buf,SND_ASYNC);         // and play it...
  4750. }
  4751.  
  4752. int DiskOK(void)
  4753. {
  4754.     struct  dfree   df;
  4755.     long    bavail, picsize, xdim, ydim;
  4756.  
  4757.     xdim = hres - 50;
  4758.     ydim = vres - 50;
  4759.     // double the x*y dimension just to be safe in case
  4760.     // the RLE compression algorithm screws up.
  4761.     picsize = (xdim * ydim) * 2;
  4762.     // default disk...
  4763.     getdfree(0,&df);
  4764.     bavail = ((long)(df.df_bsec * df.df_sclus)) * df.df_avail;
  4765.     if(bavail < (savelevel + picsize)){
  4766.        MessageBox(hWndMain,"Not enough space to Save!","Uh Oh!", MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  4767.        return (0);
  4768.     }
  4769.     return (1);
  4770. }
  4771.  
  4772. void chthedir(int thedir)
  4773. {
  4774.      if(thedir == IN){
  4775.     setdisk(indrive);
  4776.     chdir(ourdir);
  4777.      }
  4778.      else{
  4779.         setdisk(outdrive);
  4780.     chdir(outdir);
  4781.      }
  4782. }
  4783.  
  4784.  
  4785. void DrawLine(int x1, int y1, int x2, int y2, int Width, COLORREF Color)
  4786. {
  4787.      HDC          hdc;
  4788.      HPALETTE     oldpal;
  4789.      HPEN         hPen, oldpen;
  4790.      int          i, j, k;
  4791.  
  4792.  
  4793.      hdc = GetDC(phwnd);
  4794.      oldpal = SelectPalette(hdc, hwndpal, FALSE);
  4795.      RealizePalette(hdc);
  4796.      hPen = CreatePen(PS_SOLID, Width, Color | 0x2000000L);
  4797.      oldpen = SelectObject(hdc,hPen);
  4798.      Line(hdc,x1,y1,x2,y2);
  4799.      SelectObject(hdc,oldpen);
  4800.      SelectPalette(hdc, oldpal, FALSE);
  4801.      ReleaseDC(phwnd,hdc);
  4802.      DeleteObject(hPen);
  4803. }
  4804.  
  4805.